Results 1 to 7 of 7

Thread: Help with IF statement

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    11

    Help with IF statement

    I have two problems here that should be easy but I'm stumped.

    1.) I need a If statement that says IF label3(SP + 3) = 2.2 and Label3(SP+!) ="####82-#" then it should pop up a passed on a box. If those both are not true then it should popup a box saying INCORRECT. VB6 does not like my + .. any ideas?

    2.) Also on the Label3(SP+1).Caption = "####82-#" the # means random numbers that can change, but the 82 won't. That is what I want the If statement to check to see if that 82 is in the 5th and 6th spot while ignoring the others where the # and - are. Any ideas?

    Thank you!!!!

    Code:
      If Label3(SP + 3).Caption = "2.2" + Label3(SP + 1).Caption = "####82-#" Then
        MsgBox ("Diameter and Carbon Passed!")
        Else
        MsgBox ("STOP! INCORRECT CARBON AND DIAMETER MATCH! CONTACT SUPERVISOR NOW!")
        End If

  2. #2

  3. #3

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    11

    Re: Help with IF statement

    Thank you for the quick response. It worked greatly. If I wanted to add another If in there, like

    Code:
      If Label3(SP + 3).Caption = "2.16" And Mid$(Label3(SP + 1).Caption, 5, 2) = "72" Then
        MsgBox ("Diameter and Carbon Passed!")
        Else
        MsgBox ("STOP! INCORRECT CARBON AND DIAMETER MATCH! CONTACT SUPERVISOR NOW!")
        End
        End If
    Where it also looks for 2.16 and ="72", on top of the 2.20 and = "82", how would you code that?


    Would it look something like

    Code:
      If Label3(SP + 3).Caption = "2.20" And Mid$(Label3(SP + 1).Caption, 5, 2) = "82" OR If Label3(SP + 3).Caption = "2.16" And Mid$(Label3(SP + 1).Caption, 5, 2) = "72" Then
        MsgBox ("Diameter and Carbon Passed!")
        Else
        MsgBox ("STOP! INCORRECT CARBON AND DIAMETER MATCH! CONTACT SUPERVISOR NOW!")
        End
        End If
    ?

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Help with IF statement

    Quote Originally Posted by MartinLiss View Post
    If Label3(SP + 3).Caption = "2.2" And Mid$(Label3(SP + 1).Caption,5 2) = "82" Then
    If the length & format of (SP+1) can vary, then maybe this:
    Code:
    If Label3(SP + 3).Caption = "2.2" And InStr(Label3(SP + 1).Caption, "82-") Then
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Help with IF statement

    Zach

    It probably should look like this -- ie, use parentheses, and eliminate
    the 2nd 'If'

    Code:
    If (Label3(SP + 3).Caption = "2.20" And Mid$(Label3(SP + 1).Caption, 5, 2) = "82") _ 
    Or (Label3(SP + 3).Caption = "2.16" And Mid$(Label3(SP + 1).Caption, 5, 2) = "72") Then
        MsgBox ("Diameter and Carbon Passed!")
    Else
        MsgBox ("STOP! INCORRECT CARBON AND DIAMETER MATCH! CONTACT SUPERVISOR NOW!")
        End
    End If
    Spoo

  7. #7

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