Ask Experts Questions for FREE Help!
 

Free Answers in 3 Easy Steps

Register Now
3 Steps
 


Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.
  View Answers    Answer this question    Ask a question  
 

neo_lover2000
Jun 10, 2009, 06:44 PM
Sir I make something like these, check because there is an error when = is pressed
Anyway i'll try your program

Dim first, second As Long
Dim num1, num2 As Long
Dim sign As String
Dim add, minus As Boolean
Dim FirstValueEntered As Boolean

Private Sub Command1_Click(Index As Integer)
If FirstValueEntered = True Then
num2 = num2 & Command1(Index).Caption
TextDisplay.Text = num2
Else
num1 = num1 & Command1(Index).Caption
TextDisplay.Text = num1
End If
End Sub

Private Sub cmdPlus_Click()
Add = True
If minus = True Then
If (FirstValueEntered) And (num2 <> 0) Then
first = Val(num1)
second = Val(num2)
first = first - second
TextDisplay.Text = first
second = 0
num2 = 0
num1 = first
ElseIf num1 <> 0 Then
FirstValueEntered = True
sign = cmdMinus.Caption
End If
minus = False
' for addition
If (FirstValueEntered) And (num2 <> 0) Then
first = Val(num1)
second = Val(num2)
first = first + second
TextDisplay.Text = first
second = 0
num2 = 0
num1 = first
ElseIf num1 <> 0 Then
FirstValueEntered = True
sign = cmdPlus.Caption
End If
Else
If (FirstValueEntered) And (num2 <> 0) Then
first = Val(num1)
second = Val(num2)
first = first + second
TextDisplay.Text = first
second = 0
num2 = 0
num1 = first
ElseIf num1 <> 0 Then
FirstValueEntered = True
sign = cmdPlus.Caption
End If
End If
End Sub

Private Sub cmdMinus_Click()
Minus = True
If add = True Then
If (FirstValueEntered) And (num2 <> 0) Then
first = Val(num1)
second = Val(num2)
first = first + second
TextDisplay.Text = first
second = 0
num2 = 0
num1 = first
ElseIf num1 <> 0 Then
FirstValueEntered = True
sign = cmdPlus.Caption
End If
add = False
'for substraction
If (FirstValueEntered) And (num2 <> 0) Then
first = Val(num1)
second = Val(num2)
first = first - second
TextDisplay.Text = first
second = 0
num2 = 0
num1 = first
ElseIf num1 <> 0 Then
FirstValueEntered = True
sign = cmdMinus.Caption
End If
Else
If (FirstValueEntered) And (num2 <> 0) Then
first = Val(num1)
second = Val(num2)
first = first - second
TextDisplay.Text = first
second = 0
num2 = 0
num1 = first
ElseIf num1 <> 0 Then
FirstValueEntered = True
sign = cmdMinus.Caption
End If
End If
End Sub

Private Sub cmdC_Click()
TextDisplay.Text = ""
Num1 = Null
Num2 = 0
First = 0
Second = 0
FirstValueEntered = False
End Sub

Private Sub cmdEq_Click()
First = Val(num1) 'an error occur in this line, because of the null value of num1
If num1 = Null Then 'i try to use this line to counter the error
TextDisplay = "?" 'nothing happend
MsgBox "enter number" 'maybe you have something to correct the error
End If
If num2 <> 0 Then
second = Val(num2)
Else
second = 0
End If
Select Case sign
Case "+"
TextDisplay.Text = first + second
Case "-"
TextDisplay.Text = first - second
End Select
If num1 = 0 Or num2 = 0 Then
TextDisplay = "?"
MsgBox "enter number"
End If
Second = 0
Num1 = first
FirstValueEntered = True
End Sub

Private Sub Form_Load()
TextDisplay.Text = ""
Num1 = Null
Num2 = 0
First = 0
Second = 0
FirstValueEntered = False

End Sub

Perito
Jun 11, 2009, 10:31 AM
Add this at the top of Sub cmdEq_Click:

Private Sub cmdEq_Click()
If IsNull(num1) Then
Exit Sub
End If