Please follwing below steps :
Open Visual Basic 6.0
Standard EXE - Click Open
And then design form1 like below picture
and then please place below code in Form1 :
Private Sub Form_Load()
Text1 = ""
Text2 = ""
Text3 = ""
Text3.Enabled = False
End Sub
Private Sub Command1_Click()
If Text1 = "" Or Text2 = "" Then
MsgBox "Please Fill First and Second Text"
Text1.SetFocus
Else
Text3 = Val(Text1) + Val(Text2)
End If
End Sub
Private Sub Command2_Click()
If Text1 = "" Or Text2 = "" Then
MsgBox "Please Fill First and Second Text"
Text1.SetFocus
Else
Text3 = Text1 - Text2
End If
End Sub
Private Sub Command3_Click()
If Text1 = "" Or Text2 = "" Then
MsgBox "Please Fill First and Second Text"
Text1.SetFocus
Else
Text3 = Text1 * Text2
End If
End Sub
Private Sub Command4_Click()
If Text1 = "" Or Text2 = "" Then
MsgBox "Please Fill First and Second Text"
Text1.SetFocus
Else
Text3 = Text1 / Text2
End If
End Sub
Private Sub Text1_KeyPress(Keyascii As Integer)
If Keyascii = 13 Then Text2.SetFocus
If Not (Keyascii >= Asc("0") And Keyascii <= Asc("9") Or Keyascii = vbKeyBack Or Keyascii = vbKeyReturn) Then Keyascii = 0
End Sub
Private Sub Text2_KeyPress(Keyascii As Integer)
If Keyascii = 13 Then Command1.SetFocus
If Not (Keyascii >= Asc("0") And Keyascii <= Asc("9") Or Keyascii = vbKeyBack Or Keyascii = vbKeyReturn) Then Keyascii = 0
End Sub
and the last, please run your project
CLICK HERE to download tutorial above
0 Response to "Create a Simple Calculator in Visual Basic 6.0"