请求帮忙解释这段VB代码的意思

来源:百度知道 编辑:UC知道 时间:2024/05/16 10:26:35
初学,有些地方隐隐约约知道是干什么用的,但又不很懂,程序是一个计算器,代码如下:Private cal As String
Private ss(2) As String
Private s As Integer
Private Sub Command1_Click(Index As Integer)
If s = 0 Then
s = 1
Text1.Text = CStr(Index)
ss(s) = ss(s) + CStr(Index)
Else
Text1.Text = Text1.Text + CStr(Index)
ss(s) = ss(s) + CStr(Index)
End If
End Sub
Private Sub Command2_Click()
If s = 1 Then
cal = "+"
s = s + 1
Text1.Text = Text1.Text + "+"
End If
End Sub
Private Sub Command3_Click()
If s = 1 Then
cal = "-"
s = s + 1
Text1.Text = Text1.Text + "-"
End If
End Sub
Private Sub Command4_Click()
Text1.Text = 0
s = 0
ss(1) = 0
ss(2) = 0
End Sub
Private Sub Command5_Click()
If s = 2 Then
Select Case cal
Case &q

'从代码总体看,这是一个计算其的程序
'按钮1数组应该是10个分别代表0~9的数字
'按钮2是加号,按钮3是减号,按钮6是乘号,按纽7是除号
'按钮4是清除,按纽5是等号,文本框是输入和输出的显示

Private cal As String '声明cal为字符串型变量
Private ss(2) As String '声明ss为由三个元素字符串型数组变量
Private s As Integer '声明s是一个整型变量

Private Sub Command1_Click(Index As Integer) '按钮1数组(多个按钮公用这一个名字)被单击
If s = 0 Then
s = 1
Text1.Text = CStr(Index) '把按钮序号写进文本框并存进ss字符串
ss(s) = ss(s) + CStr(Index)
Else
Text1.Text = Text1.Text + CStr(Index) '把按钮序号写进文本框并存进ss字符串
ss(s) = ss(s) + CStr(Index)
End If
End Sub

Private Sub Command2_Click() '按钮2被单击
If s = 1 Then
cal = "+"
s = s + 1
Text1.Text = Text1.Text + "+" '文本框里写一个加号
End If
End Sub
Private Sub Command3_Click() '按钮3被单击
If s = 1 Then
cal = "-"
s = s + 1
Text1.Text = Text1.Text + "-" '文本框写一个减号
End If
End Sub