Jump to content

conditional logic


Recommended Posts

i have three combo boxes. (A B C)

trying to get the user to set a path A.B.C

"?" = literally a question mark that indicates no value selected

if the user picks "?" on A

then the path should be: B.C

if the user picks "?" on B

then the path should be C (bc A.?.C is invalid)

so i get this all right BUT i cant get a value if the user does not select a question mark

A.B.C

hope im making sense

If GUICtrlRead($a) = "?" Then

$npath=(GUICtrlRead($:) & "." & GUICtrlRead($c))

EndIf

If GUICtrlRead($:) = "?" Then

$npath=(GUICtrlRead($c))

EndIf

If NOT GUICtrlRead($a) = "?" OR GUICtrlRead($:) = "?" Then

$npath=(GUICtrlRead($a) & "." & GUICtrlRead($:P & "." & GUICtrlRead($c))

EndIf

Link to comment
Share on other sites

Do I get it right that the user can only select one questionmark?

In that case you can use an elseif statement like this (or a case select statement in a similar way):

If GUICtrlRead($a) = "?" Then
    $npath=(GUICtrlRead($B) & "." & GUICtrlRead($c))
ElseIf GUICtrlRead($B) = "?" Then
    $npath=(GUICtrlRead($c))
Else
    $npath=(GUICtrlRead($a) & "." & GUICtrlRead($B) & "." & GUICtrlRead($c))
EndIf

If the user can select more than one questionmark, you can use set it up for example this will not work

In the beginning there was nothing and then even that exploded - anonymous

Link to comment
Share on other sites

they should be able to use more than one question mark

A or B

Do I get it right that the user can only select one questionmark?

In that case you can use an elseif statement like this (or a case select statement in a similar way):

If GUICtrlRead($a) = "?" Then
    $npath=(GUICtrlRead($B) & "." & GUICtrlRead($c))
ElseIf GUICtrlRead($B) = "?" Then
    $npath=(GUICtrlRead($c))
Else
    $npath=(GUICtrlRead($a) & "." & GUICtrlRead($B) & "." & GUICtrlRead($c))
EndIf

If the user can select more than one questionmark, you can use set it up for example this will not work

Link to comment
Share on other sites

The solution of Zorphnog will be nice, but if you like the structure I proposed earlier, you can use a second condition after the first If statement:

If GUICtrlRead($a) = "?" Then
    If GUICtrlRead($B) = "?" Then
        $npath=(GUICtrlRead($c))
    Else
        $npath=(GUICtrlRead($B) & "." & GUICtrlRead($c))
    EndIf
ElseIf GUICtrlRead($B) = "?" Then
    $npath=(GUICtrlRead($c))
Else
    $npath=(GUICtrlRead($a) & "." & GUICtrlRead($B) & "." & GUICtrlRead($c))
EndIf

In the beginning there was nothing and then even that exploded - anonymous

Link to comment
Share on other sites

That works DMEEE!!

thanks man

The solution of Zorphnog will be nice, but if you like the structure I proposed earlier, you can use a second condition after the first If statement:

If GUICtrlRead($a) = "?" Then
    If GUICtrlRead($B) = "?" Then
        $npath=(GUICtrlRead($c))
    Else
        $npath=(GUICtrlRead($B) & "." & GUICtrlRead($c))
    EndIf
ElseIf GUICtrlRead($B) = "?" Then
    $npath=(GUICtrlRead($c))
Else
    $npath=(GUICtrlRead($a) & "." & GUICtrlRead($B) & "." & GUICtrlRead($c))
EndIf
Link to comment
Share on other sites

Case statements are also ideal for this to help follow the logical flow.

Also, it's easier code writing if you do all your GuiControlRead()s at the start of you evaluation and assign them to variables.

$aVal = GUICtrlRead($a)
    $bVal = GUICtrlRead($B)
    $cVal = GUICtrlRead($c)
    Select 
        Case $aVal = "?" AND $bVal = "?" AND $cVal = "?"
            ;Invalid selection, error handling or loop continuation here 
        Case $aVal ="?" AND $bVal ="?" 
            $npath = $cVal
        Case $aVal = "?" AND $cVal = "?"
            $npath= $bVal
        Case $aVal = "?" 
            $npath = $bVal & "." & $cVal
        Case $aVal <> "?" AND $bVal <> "?" AND $cVal <> "?"
            $npath= $aVal & "." & $bVal & "." & $cVal
    EndSelect
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...