Help - Search - Members - Calendar
Full Version: how do you do multiple else, if commands? (SOLVED)
The CD Forum > The CD Forum > WinBuilder
royalbox
As the title says, how do you do multiple else, if commands?

I've tried:
CODE
If,%pRadioGroup1%,Equal,0,Begin
  Message,0,INFORMATION
  Else,If,%pRadioGroup1%,Equal,1,Message,1,INFORMATION
  Else,If,%pRadioGroup1%,Equal,2,Message,2,INFORMATION
  Else,If,%pRadioGroup1%,Equal,3,Message,3,INFORMATION
  Else,If,%pRadioGroup1%,Equal,4,Message,4,INFORMATION
End

But only the first option is executed.

I thank thee.
psc
QUOTE (royalbox @ Feb 3 2009, 01:28 AM) *
As the title says, how do you do multiple else, if commands?

I've tried:
CODE
If,%pRadioGroup1%,Equal,0,Begin
   Message,0,INFORMATION
   Else,If,%pRadioGroup1%,Equal,1,Message,1,INFORMATION
   Else,If,%pRadioGroup1%,Equal,2,Message,2,INFORMATION
   Else,If,%pRadioGroup1%,Equal,3,Message,3,INFORMATION
   Else,If,%pRadioGroup1%,Equal,4,Message,4,INFORMATION
End

But only the first option is executed.

I thank thee.

Only 'If' is a statement, Else is none.

Syntax: If,<Condition>,<statement>[<newline>Else,<statement>]
<statement> cab be a Begin - End block

CODE
If,%pRadioGroup1%,Equal,0,Begin
  Message,0,INFORMATION
End
Else,Begin
  If,%pRadioGroup1%,Equal,1,Message,1,INFORMATION
End
Else,Begin
  If,%pRadioGroup1%,Equal,2,Message,2,INFORMATION
End
Else,Begin
  If,%pRadioGroup1%,Equal,3,Message,3,INFORMATION
End
Else,Begin
  If,%pRadioGroup1%,Equal,4,Message,4,INFORMATION
End

But in this case it would bea easier to use:
So your code should look like:
CODE
If,%pRadioGroup1%,Equal,0,Message,0,INFORMATION
If,%pRadioGroup1%,Equal,1,Message,1,INFORMATION
If,%pRadioGroup1%,Equal,2,Message,2,INFORMATION
If,%pRadioGroup1%,Equal,3,Message,3,INFORMATION
If,%pRadioGroup1%,Equal,4,Message,4,INFORMATION

That is not measurable slower.

Peter
Ed_P
Would this not work?

CODE
If %pRadioGroup1% Equal 0 (
  Message 0 INFORMATION
) Else (
  If %pRadioGroup1% Equal 1 Message 1 INFORMATION
) Else (
  If %pRadioGroup1% Equal 2 Message 2 INFORMATION
) Else (
  If %pRadioGroup1% Equal 3 Message 3 INFORMATION
)Else (
  If %pRadioGroup1% Equal 4 Message 4 INFORMATION
)


Although maybe this?

CODE
If %pRadioGroup1% Equal 0 (Message 0 INFORMATION)
  Else
  If %pRadioGroup1% Equal 1 (Message 1 INFORMATION)
    Else
    If %pRadioGroup1% Equal 2 (Message 2 INFORMATION)
      Else
      If %pRadioGroup1% Equal 3 (Message 3 INFORMATION)
        Else
        If %pRadioGroup1% Equal 4 (Message 4 INFORMATION)


Don't ya hate it when structure interferes with esthetics? Or maybe it's the other way around.
psc
QUOTE (Ed_P @ Feb 3 2009, 06:04 PM) *
Would this not work?

CODE
If %pRadioGroup1% Equal 0 (
   Message 0 INFORMATION
) Else (
   If %pRadioGroup1% Equal 1 Message 1 INFORMATION
) Else (
   If %pRadioGroup1% Equal 2 Message 2 INFORMATION
) Else (
   If %pRadioGroup1% Equal 3 Message 3 INFORMATION
)Else (
   If %pRadioGroup1% Equal 4 Message 4 INFORMATION
)


Although maybe this?

CODE
If %pRadioGroup1% Equal 0 (Message 0 INFORMATION)
   Else
   If %pRadioGroup1% Equal 1 (Message 1 INFORMATION)
     Else
     If %pRadioGroup1% Equal 2 (Message 2 INFORMATION)
       Else
       If %pRadioGroup1% Equal 3 (Message 3 INFORMATION)
         Else
         If %pRadioGroup1% Equal 4 (Message 4 INFORMATION)


Don't ya hate it when structure interferes with esthetics? Or maybe it's the other way around.

On the first view it sounds reasonable.
But two concerns:
#1: Also in 'standard' languages with nested If, Else (or similar) it is sometimes necessary to include begin - end or { - } or whatelse to tell the compiler the logical dependencies.
#2: The valid syntax which is used by WinBuilder, I explained in my post above. If a different syntax works, that may be fine, but can be changed in the next release. The developers only hold compatibility with valid syntax, not with wrong syntax which by random worked as wanted.

The difference is that in your suggestion every Else is related to the first 'If', in the current WinBuilder syntax to the actual 'If'.
What's 'valid'?

Not a concern, but #3:
Is there anything you cannot explain with the WinBuilder syntax?
If yes, please post a sample.

Peter
royalbox
Thanks a lot chaps, I'm fairly used to the c/c++ way of doing it which doesn't use begin and end as I'm sure you know. Ed_P's 1st suggestion looks sensible to me, but if it's not the winbuilder way then I'll just do it the way Peter suggests and not worry about the redundant checking as it's only 5 or 6 checkboxes.

Thanks for your help.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.