Sign in to follow this  
Followers 0
dinodod

using ORs in IF statement

8 posts in this topic

I haven't come across any examples of a IF statement with an OR in the expression and I was wondering if anyone could advise me on what I need to do to make this work please.

If (StringLeft($var, 2) <> "KB" or StringInStr($var, "Installshield") = 0) then

$App = $App & Chr(13) & $var

EndIf

I've tried putting the () around each expression but that didn't work either.

If (StringLeft($var, 2) <> "KB") or (StringInStr($var, "Installshield") = 0) then

Thx!


Digital Chaos - Life as we know it today.I'm a Think Tank. Problem is, my tank is empty.The Quieter you are, the more you can HearWhich would you choose - Peace without Freedom or Freedom without Peace?Digital Chaos Macgyver ToolkitCompletely Dynamic MenuSQLIte controlsAD FunctionsEXCEL UDFPC / Software Inventory UDFPC / Software Inventory 2GaFrost's Admin Toolkit - My main competitor :)Virtual SystemsVMWAREMicrosoft Virtual PC 2007

Share this post


Link to post
Share on other sites



I believe what you are looking for is more:

if a=b or a=c or d=3 then

rather than

if a=b or c then

the complete expression is needed for all instances

Share this post


Link to post
Share on other sites

See if this helps explain what your code is doing:

$App = "app"
$var = "KBInstallshield"

MsgBox(0, "StringLeft", StringLeft($var, 2))
MsgBox(0, "StringInStr", StringInStr($var, "Installshield"))

If StringLeft($var, 2) <> "KB" Or StringInStr($var, "Installshield") = 0 Then
    $App = $App & Chr(13) & $var
EndIf

MsgBox(0, "$App", $App)

If $var = "KBInstallshield" then StringLeft($var, 2) <> "KB" will be false

If $var = "KBInstallshield" then StringInStr($var, "Installshield") will return 3

StringInStr($var, "Installshield") = 0 will be false

3 = 0 will be false

If both conditions are false, then $App = $App & Chr(13) & $var never executes.

Change $var = "KBInstallshield" to $var = "KBInstall shield" and see what happens...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

To explain how to look at OR and AND conditions you may consider this:

True OR True = True

True OR False = True

False OR True = True

False OR False = False

True AND True = True

True AND False = False

False AND True = False

False AND False = False

:whistle:


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

The OR part has always baffled me aswell:

$a = 1
If $a = 2 OR $a = 3 Then
    MsgBox(0, "Ifs", "If statement true")
EndIfoÝ÷ Ù8Z·
+Çâì!z}7éoÝ÷ Ø   mêÚ¶+Þ&§vwµêì¶)ejëh×6If $a OR $b = (2 OR 3 OR 4)

Thanks to any and all who read that.. just remember folks, it does NOT actually work that way.. it works how all these other people have suggested :whistle:

/tAKTelapis

Share this post


Link to post
Share on other sites

...what I need to do to make this work please.

What is the result that you expect?

What is the value of $var?

...

Switch to an alternative If needed.

$a = 2

Switch $a
    Case 2, 3, 4
        MsgBox(0, '', 'True')
    Case Else
        MsgBox(0, '', 'False')
EndSwitch

:whistle:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0