Jump to content

Recommended Posts

Posted

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?

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Posted

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.

Posted

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)

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
×
×
  • Create New...