如何用VB做一个类似计算器的余额累加器

一个计数器,有两个text控件,还有0~9是command控件,还有两个command是+和-,要的效果是按0~9的数字,显示在一个text控件中,可以是2位数、3位数的... 一个计数器,有两个text控件,还有0~9是command控件,还有两个command是+和-,要的效果是按0~9的数字,显示在一个text控件中,可以是2位数、3位数的,然后按+或-,在另外一个text控件中会根据+或-加上或减去相应的数字,然后得出最后的答案。 展开
 我来答
zUfs6652
2008-10-25 · TA获得超过4217个赞
知道小有建树答主
回答量:1431
采纳率:0%
帮助的人:1292万
展开全部
用记事本复制一下内容到 XXXX.frm 打开即可
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4095
ClientLeft = 60
ClientTop = 450
ClientWidth = 3810
LinkTopic = "Form1"
ScaleHeight = 4095
ScaleWidth = 3810
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command4
Caption = "清空"
Height = 495
Left = 2280
TabIndex = 14
TabStop = 0 'False
Top = 2640
Width = 1215
End
Begin VB.CommandButton Command3
Caption = "-"
Height = 495
Left = 2160
TabIndex = 13
TabStop = 0 'False
Top = 3360
Width = 1335
End
Begin VB.CommandButton Command2
Caption = "+"
Height = 495
Left = 360
TabIndex = 12
TabStop = 0 'False
Top = 3360
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 375
Index = 9
Left = 2640
TabIndex = 11
TabStop = 0 'False
Top = 2160
Width = 975
End
Begin VB.CommandButton Command1
Caption = "8"
Height = 375
Index = 8
Left = 1440
TabIndex = 10
TabStop = 0 'False
Top = 2160
Width = 975
End
Begin VB.CommandButton Command1
Caption = "7"
Height = 375
Index = 7
Left = 240
TabIndex = 9
TabStop = 0 'False
Top = 2160
Width = 975
End
Begin VB.CommandButton Command1
Caption = "6"
Height = 375
Index = 6
Left = 2640
TabIndex = 8
TabStop = 0 'False
Top = 1680
Width = 975
End
Begin VB.CommandButton Command1
Caption = "5"
Height = 375
Index = 5
Left = 1440
TabIndex = 7
TabStop = 0 'False
Top = 1680
Width = 975
End
Begin VB.CommandButton Command1
Caption = "4"
Height = 375
Index = 4
Left = 240
TabIndex = 6
TabStop = 0 'False
Top = 1680
Width = 975
End
Begin VB.CommandButton Command1
Caption = "9"
Height = 375
Index = 3
Left = 2640
TabIndex = 5
TabStop = 0 'False
Top = 1200
Width = 975
End
Begin VB.CommandButton Command1
Caption = "2"
Height = 375
Index = 2
Left = 1440
TabIndex = 4
TabStop = 0 'False
Top = 1200
Width = 975
End
Begin VB.CommandButton Command1
Caption = "1"
Height = 375
Index = 1
Left = 240
TabIndex = 0
TabStop = 0 'False
Top = 1200
Width = 975
End
Begin VB.CommandButton Command1
Caption = "0"
Height = 495
Index = 0
Left = 480
TabIndex = 3
TabStop = 0 'False
Top = 2640
Width = 1335
End
Begin VB.TextBox Text2
Alignment = 1 'Right Justify
Enabled = 0 'False
Height = 375
Left = 2640
TabIndex = 2
Top = 360
Width = 975
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Enabled = 0 'False
Height = 375
Left = 480
TabIndex = 1
Top = 360
Width = 1935
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Leiji As Long

Private Sub Command1_Click(Index As Integer)
Text1.Text = Val(Text1.Text & Command1(Index).Caption)
End Sub

Private Sub Command2_Click()
If Len(Text1.Text) < 1 Then
MsgBox "只能输入2到3位数字"
Else
Leiji = Leiji + Text1.Text
Text2.Text = Leiji
End If
End Sub

Private Sub Command3_Click()
If Len(Text1.Text) < 1 Then
MsgBox "只能输入2到3位数字"
Else
Leiji = Leiji - Text1.Text
Text2.Text = Leiji
End If
End Sub

Private Sub Command4_Click()
Text1.Text = ""
End Sub

Private Sub Form_Load()
Text1.MaxLength = 3 '限制最多输入3位
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式