kor Posted January 19, 2011 Share Posted January 19, 2011 if I have 6 variables. I want to check all 6 variables and make sure that none of them are blank. If any of the 6 are blank then exit. What is the most efficient way to do that? Case? If with multiple OR's? $var1 = "something" $var2 = "awful" $var3 = "this" $var4 = "way" $var5 = "comes" If $var1 = "" Or $var2 = "" Or $var3 = "" Or $var4 = "" Or $var5 = "" Then ;exit Else ; continue EndIf Is there a more efficient way to do the above? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 19, 2011 Moderators Share Posted January 19, 2011 kor, I would put the variables in an array and use a loop: Global $var[6] $var[1] = "something" $var[2] = "awful" $var[3] = "this" $var[4] = "way" $var[5] = "comes" For $i = 1 To 5 If $var[$i] = "" Then MsgBox(0, "Ooops", "Variable " & $i & " is blank") Exit EndIf Next MsgBox(0, "All OK", "All variables filled") M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kor Posted January 19, 2011 Author Share Posted January 19, 2011 Perfect. The variables are already in an array so that works out. Link to comment Share on other sites More sharing options...
Zedna Posted January 19, 2011 Share Posted January 19, 2011 (edited) If $var1 & $var2 & $var3 & $var4 & $var5 = "" Then ; all empty Else ; some not empty EndIf Edited January 19, 2011 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
kor Posted January 19, 2011 Author Share Posted January 19, 2011 Zedna, that wouldnt work. That code says if ALL vars are empty. my code above shows that something must happen if ANY var is empty. Link to comment Share on other sites More sharing options...
Zedna Posted January 19, 2011 Share Posted January 19, 2011 Zedna, that wouldnt work. That code says if ALL vars are empty. my code above shows that something must happen if ANY var is empty.Then sorry I misunderstood it. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
kylomas Posted January 19, 2011 Share Posted January 19, 2011 kor, substitute "or" for the "and" and zedna's example seems like it works.. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
KaFu Posted January 19, 2011 Share Posted January 19, 2011 If you know the array size ahead and it's a highly repetitive task... Global $var[6] $var[1] = "something" $var[2] = "awful" $var[3] = "this" $var[4] = "way" $var[5] = "comes" $timer = TimerInit() For $i = 1 To 1000000 If Not $var[1] Or Not $var[2] Or Not $var[3] Or Not $var[4] Or Not $var[5] Then For $y = 1 To 5 If $var[$y] = "" Then MsgBox(0, "Ooops", "Variable " & $y & " is blank") Exit EndIf Next EndIf Next ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() For $i = 1 To 1000000 For $y = 1 To 5 If $var[$y] = "" Then MsgBox(0, "Ooops", "Variable " & $y & " is blank") Exit EndIf Next Next ConsoleWrite(TimerDiff($timer) & @CRLF) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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