Results 1 to 20 of 20

Thread: and/or statement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    London, Uk.
    Posts
    72

    and/or statement

    Can you clarify what does this statement mean, as I'm getting really confused with the and/or:

    if InStr(Label2.Caption, "SSL + SET") And _
    InStr(Label2.Caption, "digital cash") Or _
    InStr(Label2.Caption, "SSL + SET") Then

    Does it mean if either SSL + digital cash is selected then.....?

    Thanks.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    If the caption contains "SSL + SET" And it also contains "digital cash"

    or if the caption contains "SSL + SET" then

    do something.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: and/or statement

    Originally posted by P Lee
    Can you clarify what does this statement mean, as I'm getting really confused with the and/or:

    if InStr(Label2.Caption, "SSL + SET") And _
    InStr(Label2.Caption, "digital cash") Or _
    InStr(Label2.Caption, "SSL + SET") Then

    Does it mean if either SSL + digital cash is selected then.....?

    Thanks.
    IF "SSL + SET" And "digital cash" is found, Or "SSL + SET" is found, Then....

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Form_Load()
    2. Label2.Caption = "SSL + SET" & "digital cash"
    3.  
    4. 'the first instr will return 1
    5. 'the second instr will return 10
    6. 'if u do a And operation on 1 And 10 it will return 0 (false)
    7.  
    8. If InStr(Label2.Caption, "SSL + SET") And _
    9. InStr(Label2.Caption, "digital cash") Or _
    10. InStr(Label2.Caption, "SSL + SET") Then
    11.     MsgBox "sdfasd"
    12. End If
    13. MsgBox 1 And 10
    14.  
    15. 'u should do it like this :
    16. If InStr(Label2.Caption, "SSL + SET") <> 0 And _
    17. InStr(Label2.Caption, "digital cash") <> 0 Then
    18. '.
    19. '.
    20.  
    21. End Sub
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    I tried to explain, but if this is somewhat unclear, let me know
    -= a peet post =-

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    London, Uk.
    Posts
    72

    Arrow

    thanks, in that case I want both options to be selected so I'll use:

    if InStr(Label2.Caption, "SSL + SET") And _
    InStr(Label2.Caption, "digital cash") and then


  7. #7
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190
    The AND statement "SSL , SET"
    by the And statement must by the SSL and the SET condition or value TRUE
    by the Or statement must one value by true the SSL or the SET

    that is the different between these two

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  9. #9
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by peet
    VB Code:
    1. 'u should do it like this :
    2. If InStr(Label2.Caption, "SSL + SET") <> 0 And _
    3. InStr(Label2.Caption, "digital cash") <> 0 Then
    Good point Peet, I missed that

  10. #10
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    only reason i knew is because I'v done the same thing... wish I only did it once though


    -= a peet post =-

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    London, Uk.
    Posts
    72
    sorry guys, but what does the <> actually mean in the suggested recommended code:

    If InStr(Label2.Caption, "SSL + SET") <> 0 And _
    InStr(Label2.Caption, "digital cash") <> 0 Then

    Does it mean if both are selected then........?

    If I just done this, then what is the difference?

    If InStr(Label2.Caption, "SSL + SET") And _
    InStr(Label2.Caption, "digital cash") > 0 Then

  12. #12
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    the problem is that u do a boolean operation on two integers

    eg 1 And 10 ... it does not give u the result u want.

    1 And 10 returns 0 (false)

    if u add the <> 0 then u do a operation on two expressions that either return 1 or 0

    then u get the expected result...

    1 And 1 = 1

    1 And 0 = 0

    .
    .
    .


    damn! I'm having problems explaining this

    could anyone better in english do it for me please
    -= a peet post =-

  13. #13
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking It's all about the way you walk...

    It doesn't matter.
    VB interprets 0 as False and ANYTHING else as TRUE!

    1 AND 0 = FALSE
    1 OR 0 = TRUE
    1 AND 15 = TRUE
    0 AND 15 = FALSE
    42 OR 0 =TRUE



    Does that make sense?

    So if:
    VB Code:
    1. InStr(Label2.Caption, "SSL + SET")
    is greater than 0 then it's TRUE

  14. #14
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    instead of
    VB Code:
    1. If InStr(Label2.Caption, "SSL + SET") <> 0 And InStr(Label2.Caption, "digital cash") <> 0 Or _
    2.     InStr(Label2.Caption, "SSL + SET") <> 0 Then
    3.     MsgBox "sdfasd"
    4. End If
    i would usually use brackets to make it more readable. i.e.
    VB Code:
    1. If [b]([/b]InStr(Label2.Caption, "SSL + SET") <> 0 And InStr(Label2.Caption, "digital cash") <> 0[b])[/b] Or _
    2.     InStr(Label2.Caption, "SSL + SET") <> 0 Then
    3.     MsgBox "sdfasd"
    4. End If
    although in the above example you dont need the And bit anyway, it can be left as
    VB Code:
    1. If InStr(Label2.Caption, "SSL + SET") <> 0 Or _
    2.     InStr(Label2.Caption, "SSL + SET") <> 0 Then
    3.     MsgBox "sdfasd"
    4. End If
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  15. #15

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    London, Uk.
    Posts
    72
    Thanks guys I understand now.

  17. #17
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    Originally posted by Wokawidget
    Don't you mean:
    VB Code:
    1. If (InStr(Label2.Caption, "digital cash") Or _
    2.     InStr(Label2.Caption, "SSL + SET")) Then
    3.     MsgBox "sdfasd"
    4. End If
    nope

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  18. #18
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Re: It's all about the way you walk...

    Originally posted by Wokawidget
    It doesn't matter.
    VB interprets 0 as False and ANYTHING else as TRUE!

    1 AND 0 = FALSE
    1 OR 0 = TRUE
    1 AND 15 = TRUE
    0 AND 15 = FALSE
    42 OR 0 =TRUE



    Does that make sense?

    So if:
    VB Code:
    1. InStr(Label2.Caption, "SSL + SET")
    is greater than 0 then it's TRUE
    VB Code:
    1. Private Sub Command1_Click()
    2.     MsgBox 1 And 12 '( 1 And 1100 = 0
    3.     MsgBox 1 And 13 '( 1 and 1101 = 1
    4.     MsgBox 1 And 14 '( 1 and 1110 = 0
    5.     MsgBox 1 And 15 '( 1 and 1111 = 1
    6.     MsgBox 1 And 16 '( 1 and 10001 = 0
    7. End Sub

    I assume u agree to this ?

    It does matter what u And with what ...
    -= a peet post =-

  19. #19
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by darre1
    ...although in the above example you dont need the And bit anyway, it can be left as
    VB Code:
    1. If InStr(Label2.Caption, "SSL + SET") <> 0 Or _
    2.     InStr(Label2.Caption, "SSL + SET") <> 0 Then
    3.     MsgBox "sdfasd"
    4. End If
    errrr...doest this equate to:
    VB Code:
    1. If InStr(Label2.Caption, "SSL + SET") <> 0 Then
    2.     MsgBox "sdfasd"
    3. End If



    (a AND b) OR b = a OR b
    b OR b = b
    (a OR b) AND b = b
    (a AND b) AND b = a AND b


    Good old kaunaugh maps...spelling is incorrect

  20. #20
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    Originally posted by Wokawidget


    errrr...doest this equate to:
    VB Code:
    1. If InStr(Label2.Caption, "SSL + SET") <> 0 Then
    2.     MsgBox "sdfasd"
    3. End If



    oops
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

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