' Command3:Caption 屬性值為 Cls。' Command4:Caption 屬性值為 =。' Command5:Caption 屬性值為 Exit。 Public a, b As DoublePublic CalKey As String Private Sub Command1_Click(Index As Integer) ' 0 1 2 3 4 5 6 7 8 9 Text1.Text = Trim(Text1.Text) If Text1.Text = "0" Then Text1.Text = "" If Index <= 9 Then Text1.Text = Text1.Text & Format(Index) ElseIf Index = 10 Then Text1.Text = Text1.Text & "." End IfEnd Sub Private Sub Command2_Click(Index As Integer) ' + - * / \ a = Val(Text1.Text) Select Case Index Case 0 CalKey = "+" Case 1 CalKey = "-" Case 2 CalKey = "*" Case 3 CalKey = "/" Case 4 CalKey = "\" End Select If Index <= 3 Then Text1.Text = "" End IfEnd Sub Private Sub Command3_Click() ' Cls Text1.Text = ""End Sub Private Sub Command4_Click() ' = b = Val(Text1.Text) Select Case CalKey Case "+" Text1.Text = a + b Case "-" Text1.Text = a - b Case "*" Text1.Text = a * b Case "/" If b <> 0 Then Text1.Text = a / b Else Text1.Text = "" MsgBox "除數不能為0" End If Case "\" If b <> 0 Then Text1.Text = a Mod b Else Text1.Text = "" MsgBox "除數不能為0" End If End Select If Left(Text1.Text, 1) = "." Then Text1.Text = "0" & Text1.TextEnd Sub Private Sub Command5_Click() unloade MeEnd Sub Private Sub Form_Load()Dim i As IntegerFor i = 0 To 9 Command1(i).Caption = Format(i)NextCommand1(10).Caption = "."For i = 0 To 4 Command2(i).Caption = Mid("+-*/\", i + 1, 1)NextCommand3.Caption = "Cls"Command4.Caption = "="Command5.Caption = "Exit"Text1.Text = ""End Sub