none
Question about "Or" RRS feed

  • Question

  • I'm not sure if I am using "Or" correctly, below are two examples, the first code below has two "if" statements that work if I type "a" or "b". the second code example using "Or" only works when I type "a" but not "b", the condition is true, why does it not work?

     LinkItem1 = "a"
     MasterItemNo = "b"

    LinkItem1Q = Dialogs.AskForTextLine ("Choose an ITEM to link","Item Link")
        If LinkItem1Q = LinkItem1 Then
          Dialogs.ShowMessageBox ("A second Link item cannot be an existing item","Duplicate Links","OK","Hand")
          GraphicsWindow.ShowMessage ("it is A","title")
        EndIf
            If LinkItem1Q = MasterItemNo  Then
          Dialogs.ShowMessageBox ("A second Link item cannot be an existing item","Duplicate Links","OK","Hand")
           GraphicsWindow.ShowMessage ("it is A","title")
        EndIf

    '2nd example

    LinkItem1Q = Dialogs.AskForTextLine ("Choose an ITEM to link","Item Link")
        If LinkItem1Q = LinkItem1 Or MasterItemNo Then
          Dialogs.ShowMessageBox ("A second Link item cannot be an existing item","Duplicate Links","OK","Hand")
          GraphicsWindow.ShowMessage ("it is A or B","title")
        EndIf

    Monday, October 24, 2011 8:52 PM

Answers

  • To use the Or statement (or the And) in any compound conditional statement, either side of the Or must be a full conditional statement that evaluates to "True" or "False".

    So LinkItem1Q = LinkItem1 is either "True" or "False" OK

    But MasterItemNo is "b" and not "True" and therefore defaults to "False"

    So the compound conditional (LinkItem1Q = LinkItem1 Or MasterItemNo) will only be "True" if LinkItem1Q = LinkItem1 is "True"

    What we need I think is:

    If (LinkItem1Q = LinkItem1 Or LinkItem1Q = MasterItemNo) Then

    In this case both sides of the Or evaluate to "True" or "False" and with the Or, then the compound conditional statement is "True" if either is "True".

    • Marked as answer by SFC-P33A Monday, October 24, 2011 9:14 PM
    Monday, October 24, 2011 9:11 PM
    Moderator

All replies

  • To use the Or statement (or the And) in any compound conditional statement, either side of the Or must be a full conditional statement that evaluates to "True" or "False".

    So LinkItem1Q = LinkItem1 is either "True" or "False" OK

    But MasterItemNo is "b" and not "True" and therefore defaults to "False"

    So the compound conditional (LinkItem1Q = LinkItem1 Or MasterItemNo) will only be "True" if LinkItem1Q = LinkItem1 is "True"

    What we need I think is:

    If (LinkItem1Q = LinkItem1 Or LinkItem1Q = MasterItemNo) Then

    In this case both sides of the Or evaluate to "True" or "False" and with the Or, then the compound conditional statement is "True" if either is "True".

    • Marked as answer by SFC-P33A Monday, October 24, 2011 9:14 PM
    Monday, October 24, 2011 9:11 PM
    Moderator
  • Oh, Yes, that makes scence now, thanks for the lesson litdev.
    Monday, October 24, 2011 9:13 PM