Sign in to follow this  
Followers 0
kor

most efficient way to check multiple values then do something

8 posts in this topic

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?

Share this post


Link to post
Share on other sites



kor,

I would put the variables in an array and use a loop: :x

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Perfect. The variables are already in an array so that works out.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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)

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