Programs on usage of data types - variant, Control Arrays
Calculator
Screen DesignSource Code
Dim opt As String
Dim a As Double
Dim b As Double
Dim c As Double
Dim i As Integer
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0: Text1 = Text1 & "0"
Case 1: Text1 = Text1 & "1"
Case 2: Text1 = Text1 & "2"
Case 3: Text1 = Text1 & "3"
Case 4: Text1 = Text1 & "4"
Case 5: Text1 = Text1 & "5"
Case 6: Text1 = Text1 & "6"
Case 7: Text1 = Text1 & "7"
Case 8: Text1 = Text1 & "8"
Case 9: Text1 = Text1 & "9"
Case 10:
opt = "/"
a = Val(Text1)
Text1 = ""
Case 11:
opt = "*"
a = Val(Text1)
Text1 = ""
Case 12:
opt = "-"
a = Val(Text1)
Text1 = ""
Case 13:
opt = "+"
a = Val(Text1)
Text1 = ""
Case 14:
b = Val(Text1)
If opt = "/" Then
Text1 = a / b
ElseIf opt = "*" Then
Text1 = a * b
ElseIf opt = "-" Then
Text1 = a - b
ElseIf opt = "+" Then
Text1 = a + b
ElseIf opt = "%" Then
Text1 = a Mod b
End If
Case 15:
opt = IIf(InStr(Text1, ".") > 0, "", ".")
Text1 = Text1 & opt
If Left$(Text1, 1) = "0" Then
Text1 = Mid$(Text1, 2)
End If
Case 16:
opt = "%"
a = Val(Text1)
Text1 = ""
Case 17:
opt = "CE"
Text1 = ""
Case 18:
opt = "Backspace"
Text1 = Left(Text1, Len(Text1) - 1)
End Select
End Sub
Output