要像WINDOWS自带的那个一样,只有一个文本框的
Private Sub Command1_Click()
n = Val(Text1.Text)
m = Val(Text2.Text)
Label1.Caption = Command1.Caption
s = n + m
Text3.Text = CStr(s)
End Sub
Private Sub Command2_Click()
n = Val(Text1.Text)
m = Val(Text2.Text)
Label1.Caption = Command2.Caption
s = n - m
Text3.Text = CStr(s)
End Sub
Private Sub Command3_Click()
n = Val(Text1.Text)
m = Val(Text2.Text)
Label1.Caption = Command3.Caption
s = n * m
Text3.Text = CStr(s)
End Sub
Private Sub Command4_Click()
n = Val(Text1.Text)
m = Val(Text2.Text)
Label1.Caption = Command4.Caption
s = n / m
Text3.Text = CStr(s)
End Sub
追é®ä¸æ¯è¿ç§,å°±æ¯åWINDOWSèªå¸¦çé£ä¸ªè®¡ç®å¨ä¸æ ·åªæä¸ä¸ªææ¬æ¡ç
追çDim n As Integer
Dim ysf As String
Dim m As Integer
Dim k As Integer
Private Sub Command1_Click(Index As Integer)
For i = 0 To 3
If Command1(i).Value = True Then
ysf = Command1(i).Caption
Text1.Text = ""
k = k + 1
End If
Next i
End Sub
Private Sub Command2_Click()
If ysf = "+" Then
s = n + m
ElseIf ysf = "-" Then
s = n - m
ElseIf ysf = "*" Then
s = n * m
ElseIf ysf = "/" Then
s = n / m
End If
Text1.Text = CStr(s)
End Sub
Private Sub Command3_Click(Index As Integer)
For i = 0 To 9
If Command3(i).Value = True Then
Text1.Text = Text1.Text & Command3(i).Caption
End If
Next i
If k = 0 Then
n = Val(Text1.Text)
Else
m = Val(Text1.Text)
End If
End Sub
Private Sub Command4_Click()
Text1.Text = ""
k = 0
End Sub
ææ¯å°æ°åé®0-9ç¼åå¨command3æ§ä»¶æ°ç»ä¸ï¼+ã-ã*ã/ç¼åå¨command1æ§ä»¶æ°ç»ä¸ï¼=å·ç¼åå¨command2ä¸ï¼âæ¸
é¤âåå¨command4ä¸
两个变量保存第一操作数和第二操作数,另一个变量保存运算符号。比如:
dim opt1 as single, opt2 as single
dim strSign as string
用一个文本框作为输入面板,在用户输入数字并按加/减/乘/除后保存面板数值到opt1,保存运算符号到strSign,接下来的输入显示之前将清空面板,按等号后将当前面板的数值保存到opt2,并调用运算过程Calculate,面板显示运算结果;并将结果保存到opt1中。
过程 Calculat(varOpt1,varOpt2,varSign) 根据参数传入的两个操作数和运算符号计算并返回结果。