VB question

Sharky Forums


Results 1 to 6 of 6

Thread: VB question

  1. #1
    Reef Shark
    Join Date
    May 2002
    Posts
    267

    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

  2. #2
    Hammerhead Shark EverlastingGod's Avatar
    Join Date
    Feb 2003
    Location
    MD
    Posts
    1,364
    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.
    Stay cool
    and be somebody's fool this year

  3. #3
    Reef Shark
    Join Date
    May 2002
    Posts
    267
    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.

  4. #4
    Reef Shark
    Join Date
    May 2002
    Posts
    267
    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?

  5. #5
    Super Bunny Mod muisejt's Avatar
    Join Date
    Dec 2000
    Location
    Nova Scotia, Canada
    Posts
    9,833
    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
    If your sig is longer than your post then type more.

  6. #6
    stink palm master Fig's Avatar
    Join Date
    Dec 2000
    Posts
    3,778
    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
    Currently Playing: DOTA 2, XCOM Enemy Unknown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •