-
VB question
Hello!
I'm new to VB and am trying to create a program to compare three numbers for equality. I'm stuck at the moment. I have three text boxes. Whenever I enter three equal numbers and click the commandbox to calculate, nothing happens. Heres what I have coded so far for the cmdCalculate. Any help is appericiated.
Private Sub cmdCalculate_Click()
Dim intNumI As Variant
Dim intNumII As Variant
Dim intNumIII As Variant
intNumI = Text1
intNumII = Text2
intNumIII = Text3
If (intNumI = intNumII = intNumIII) Then
lblAnswer.Caption = "The numbers are equal"
End If
End Sub
-
What type are Text1, Text2, and Text3? If they are the text boxes then you need to get the value stored in them first. Then compare those values.
-
I don't want the values to be set. I want the user to type the value in the textbox and click calculate to determine if they are equal.
-
When I actually try setting the values for intNumI - intNumIII, nothing happens when I calculate. I have a label that should show up as "These numbers are equal", But lblAnswer.caption = "These Numbers are equal" doesn't change for some reason. Whats up? Did I code the If statement wrong?
-
If Text1, Text2, and Text3 are refering to text boxes then you need to add .Text after them, like this:
intNumI = Text1.Text
intNumII = Text2.Text
intNumIII = Text3.Text
-
Try this....
If CLng(txtOne.Text) = CLng(txtTwo.Text) And CLng(txtTwo.Text) = CLng(txtThree.Text) Then
Debug.Print "Numbers are not equal"
Else
Debug.Print "Numbers are not equal"
End If