急~~~请大虾帮忙解释下下面的程序,越详细越好!!!
发布网友
发布时间:2023-09-11 09:08
我来回答
共1个回答
热心网友
时间:2024-11-19 00:24
Dim dflag As Integer
Dim i As Integer
Dim opnre As Integer
Dim prev As Double
Dim oflag As Integer
Dim ind As Integer
以上为:定义变量为整数型变量
Private Sub Command1_Click(Index As Integer) !单击Command1,执行以下命令:
If ind = 4 Then !当变量ind=4,执行如下命令
prev = 0 !给prev变量赋值0
Text1.Text = " " !清空text1
ind = 0 !给ind变量赋值0
End If !结束判断
opnre = 0 !给变量opnre辅初值0
If oflag = 0 Then !判断
Text1.Text = " "
End If
oflag = 1 !给变量oflag辅初值0
If Command1(Index).Caption <> "." Then !若按钮index的标题不为‘.’
If Text1.Text <> " 0" Then !若text1中数据非0
Text1.Text = Text1.Text & Command1(Index).Caption !设置text1中数据为原数据Text1.Text +按钮index的标题
Else !否则
Text1.Text = " " & Command1(Index).Caption !设置text1中数据
End If
Else
If dflag = 0 Then !判断
Text1.Text = Text1.Text & "." !设置text1中数据
dflag = 1 !赋值
Else !否则
MsgBox ("ILLEGAL SAIRAM") !弹出对话框
End If
End If
End Sub
Private Sub Command2_Click(Index As Integer) !单击Command2按钮执行下列命令,基本与command1中命令雷同
If opnre = 0 Or Index = 4 Then
If ind = 0 Then
prev = prev + Val(Text1.Text)
ElseIf ind = 1 Then
prev = prev - Val(Text1.Text)
ElseIf ind = 2 Then
If Val(Text1.Text) = 0 Then !若text1中数据为0,则弹出对话框后,直接跳出command2的程序,即以下不再执行
MsgBox ("SORRY DIVIDE ZERO")
Exit Sub
Else
prev = prev / Val(Text1.Text)
End If
ElseIf ind = 3 Then
prev = prev * Val(Text1.Text)
End If
Text1.Text = Str(prev)
oflag = 0
End If
opnre = 1
ind = Index
dflag = 0
End Sub
Private Sub Command4_Click()
Text1.Text = " 0" !设置text1中数据
End Sub
Private Sub Command3_Click()
dflag = 0 !给变量赋值
prev = 0 !给变量赋值
oflag = 0 !给变量赋值
ind = 0 !给变量赋值
opnre = 0 !给变量赋值
Text1.Text = " 0" !设置text1中数据
End Sub
Private Sub Command5_Click()
If Text1.Text <> "0" And Text1.Text <> "0." Then
If Left(Text1.Text, 1) = "-" Then
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
Else
Text1.Text = "-" & Text1.Text
End If
End If
End Sub
问题补充:Private Sub Form_Load() !程序初始化
dflag = 0
prev = 0
oflag = 0
ind = 0
opnre = 0
End Sub
这是一个比较简单的VB程序,基本上就是用按钮控制text中显示的数据,可以参考VB的教材,以上用到的命令都较简单,教材里都有解释