话费充值小程序.rar
(10.18 KB)
程序代码:
Dim BB As Single, FO As Object, FT As String Private Sub Command1_Click() If Val(Text3.Text) > 10 Then Set FO = CreateObject("Scripting.FileSystemObject") FT = App.Path & "\话费.txt" If FO.FileExists(FT) = True Then Kill FT '删除原"话费.txt"文件 If Val(Text3.Text) >= 100 Then BB = BB + Val(Text3.Text) * 1.1 ElseIf Val(Text3.Text) >= 50 Then BB = BB + Val(Text3.Text) * 1.05 ElseIf Val(Text3.Text) < 50 Then BB = BB + Val(Text3.Text) End If BB = Round(BB, 2) Call BJC Text2.Text = BB Open App.Path & "\话费.txt" For Append As #1 '创建新的"话费.txt"文件 Print #1, BB Close #1 Else MsgBox "话费充值不能小于 10 元!" End If End Sub Private Sub Form_Load() Open App.Path & "\话费.txt" For Input As #1 '读取话费 Input #1, AA Close #1 BB = Round(Val(AA), 2) Call BJC Text2.Text = BB End Sub Private Sub Text1_LostFocus() ' If Val(Text1.Text) > 0 Then Set FO = CreateObject("Scripting.FileSystemObject") FT = App.Path & "\话费.txt" If FO.FileExists(FT) = True Then Kill FT '删除原"话费.txt"文件 BB = BB - Val(Text1.Text) BB = Round(BB, 2) Text2.Text = BB Text1.Text = "" Open App.Path & "\话费.txt" For Append As #1 '创建新的"话费.txt"文件 Print #1, BB Close #1 Call BJC End If End Sub Private Sub BJC() If BB < 10 And BB >= 5 Then MsgBox "金额不足,请充值!" Text1.Enabled = True ElseIf BB < 5 Then MsgBox "可用话费余额不足,无法设置话费!" Text1.Enabled = False '可用话费余额不足,“当次使用话费”文本框失效 End If If BB >= 10 Then Text1.Enabled = True End If End Sub