Results 1 to 3 of 3

Thread: My if statement being ignored...

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2004
    Posts
    3

    My if statement being ignored...

    Hello I am learning Visual Basic.net and am building simple windows applications out of a book. I am very new to this but until now have figured everything out. i have hacked at this for hours now to no avail, there might be some weird variables here and there when I was trying to improvise.

    errMessage is a text string variable that changes based on which fields are invalid

    'this way finds errors in my text fields but pops an empty error box even if the data is valid: (the debugger verifies these boolean values are all true)

    If Not test1Result Or test2Result Or test3Result Or idIsValid Then
    MessageBox.Show(errMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

    'This way will not give an error at all, even if data is invalid but the values all return true

    If (test1Result Or test2Result Or test3Result Or idIsValid) = False Then
    MessageBox.Show(errMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

    I attached the whole source code as well
    Can anyone tell me what I'm doing wrong? How can the messagebox.show command exectute if the If returns False?
    Thanks for your help
    Attached Files Attached Files

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Be sure you know the priority of the operators. For example,
    Not True or True or False or False =True
    and Not (True or True or False or False)= False
    So Not is considered sooner than Or.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Logical operators require reading . It works a little bit different than VB6 (for performance improvements) . Check the MSDN Help .

Posting Permissions

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



Click Here to Expand Forum to Full Width