| 
        
        
        
       
        
        visual basic
       
                  
        Dim first As LongDim second As Long
 Dim sign As String
 Dim FirstValueEntered As Boolean
 
 
 Private Sub Command1_Click(Index As Integer)
 If FirstValueEntered = True Then
 TextDisplay.Text = TextDisplay.Text & Command1(Index).Caption
 second = Val(TextDisplay.Text)
 Else
 TextDisplay.Text = TextDisplay.Text & Command1(Index).Caption
 first = Val(TextDisplay.Text)
 End If
 End Sub
 
 Private Sub cmdPlus_Click()
 If (FirstValueEntered) Then
 first = first + second
 TextDisplay.Text = first
 second = 0
 ElseIf TextDisplay.Text <> "" Then
 FirstValueEntered = True
 sign = cmdPlus.Caption
 TextDisplay.Text = ""
 End If
 End Sub
 
 Private Sub cmdMinus_Click()
 If (FirstValueEntered) Then
 first = first - second
 TextDisplay.Text = first
 second = 0
 ElseIf TextDisplay.Text <> "" Then
 FirstValueEntered = True
 sign = cmdMinus.Caption
 End If
 End Sub
 
 Private Sub cmdC_Click()
 TextDisplay.Text = ""
 FirstValueEntered = False
 End Sub
 
 Private Sub cmdEq_Click()
 If TextDisplay.Text <> "" Then
 second = Val(TextDisplay.Text)
 Else
 second = 0
 End If
 If sign = "+" Then
 TextDisplay = first + second
 ElseIf sign = "-" Then
 TextDisplay = first - second
 Else
 TextDisplay = "?"
 End If
 FirstValueEntered = False
 End Sub
 
 
 I would like you to check this program.
 1. if I press a number ex 1 twice it display 11
 2. if I press + once it gives command for the operation it will perform
 3. if I press a number ex 2 twice it display 22
 4. if I press + it will display the sum of the first two number,then it gives again command for the operation it will perform,
 5. if I press a number ex 1,it is appended on the number displayed, ex 33 the sum of the first two number what happened is 331.
 how can I fix it.
 thanks.
 |