AmbientMike Posted October 19, 2012 Share Posted October 19, 2012 (edited) Hopefully this will be a really quick one but I can't figure it out... I have several constants that I want to check the value of a variable against. Is there an easy way to do it in one shot or do I have to compare them all separately? For example I'd like something like this to work (but obviously it doesn't)... $var1 = "1" $var2 = "2" $var3 = "3" $var4 = "4" $var5 = "5" $var6 = 0 If $var1 <> $var2 to $var5 Then $var6 = 1 rather than have it like... $var1 = "1" $var2 = "2" $var3 = "3" $var4 = "4" $var5 = "5" $var6 = 0 If $var1 <> $var2 Then $var6 = 1 If $var1 <> $var3 Then $var6 = 1 If $var1 <> $var4 Then $var6 = 1 If $var1 <> $var5 Then $var6 = 1 Is there some syntax change that might get this to work. I have a lot of constants to check against so this would be good. Cheers. Edited October 19, 2012 by AmbientMike Link to comment Share on other sites More sharing options...
water Posted October 19, 2012 Share Posted October 19, 2012 You could use an array and do the comparison in a loop Global $aVars[4] = ["2", "3", "4", "5"] $var1 = "1" $var6 = 0 For $i = 0 to UBound($aVars, 1) - 1 If $aVars[$i] <> $var1 Then $var6 = 1 Next My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mechaflash Posted October 19, 2012 Share Posted October 19, 2012 (edited) If $var = any of the values, do nothing, or else $var6 = 1. Same concept just reversing the negatives. Switch $var1 Case $var2, $var3, $var4, $var5 Case else $var6 = 1 EndSwitch OR If $var1 <> $var2 Or $var1 <> $var3 Or $var1 <> $var4 Or $var1 <> $var 5 Then $var6 = 1 I prefer neither however. Do it water's way =P EDIT: Changed = to <> derp Edited October 19, 2012 by Mechaflash Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Tekk Posted October 20, 2012 Share Posted October 20, 2012 Another way... Local $var1 = "1" Local Const $var2 = "2" Local Const $var3 = "3" Local Const $var4 = "4" Local Const $var5 = "5" Local $var6 = 0 For $c = 2 To 5 If $var1 <> Eval('var' & $c) Then $var6 = 1 Next Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now