Source language: Translate to:

IF / ELSE / ENDIF question

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

IF / ELSE / ENDIF question

Postby dpayer » Thu Apr 26, 2012 3:29 pm

I am trying to see the error of my logic here. In a simple app with a text entry (creating variable value of [textentry1] ) and a button with the following action code:

Code: Select all
If "[textentry1]" "<>" ""

   If "[textentry1]" "=" "1"
    Alertbox "test" "you entered 1 (one)"
   Else
   If "[textentry1]" "=" "2"
    Alertbox "test" "you entered 2 (two)"
    Else
     If "[textentry1]" "=" "3"
    Alertbox "test" "you entered 3 (three)"
    Else
    If "[textentry1]" "=" "4"
    Alertbox "test" "you entered 4 (four)"
   
    Endif
Else
Alertbox "test" "you didn't enter anything!"

Endif


This is similar to some code I am using elsewhere with conditional statements within other conditional statements. I would think that if I have no value in [textentry1] when I click the button with this code, it would give me an alertbox saying "you didn't enter anthing!" but it does not work that way. If I put in 1 or 2 or 3 or 4 and click the button. It does popup as expected.

1) Is the IF / ELSE / ENDIF only meant to have one use of 'ELSE'?
2) If using a lengthy IF / ELSE / ENDIF within another IF section, does this cause a confusion?

TIA,
David P.
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Rasl » Thu Apr 26, 2012 4:42 pm

If "[textentry1]" "<>" ""
If "[textentry1]" "=" "1"
Alertbox "test" "you entered 1 (one)"
Else
If "[textentry1]" "=" "2"
Alertbox "test" "you entered 2 (two)"
Else
If "[textentry1]" "=" "3"
Alertbox "test" "you entered 3 (three)"
Else
If "[textentry1]" "=" "4"
Alertbox "test" "you entered 4 (four)"
Endif
EndIf
EndIf

EndIf
Else
Alertbox "test" "you didn't enter anything!"
Endif

salu2
Rasl
 
Posts: 129
Joined: Sat Apr 02, 2005 8:25 am
Location: Buenos Aires, Argentina

Postby Gaev » Thu Apr 26, 2012 6:06 pm

David P:

You were missing a couple of EndIf commands ... and for completeness, I added the condition where it was none of "nothing, 1, 2, 3 or 4"
Code: Select all
If "[textentry1]" "<>" ""
   If "[textentry1]" "=" "1"
      Alertbox "test" "you entered 1 (one)"
   Else
      If "[textentry1]" "=" "2"
         Alertbox "test" "you entered 2 (two)"
      Else
         If "[textentry1]" "=" "3"
            Alertbox "test" "you entered 3 (three)"
         Else
            If "[textentry1]" "=" "4"
               Alertbox "test" "you entered 4 (four)"
            Else
               Alertbox "test" "you entered something else"
            EndIf
         EndIf
      Endif
   EndIf
Else
   Alertbox "test" "you didn't enter anything!"
Endif

Put it another way ...
Code: Select all
L1:If "[textentry1]" "<>" ""
   L2:If "[textentry1]" "=" "1"
      Alertbox "test" "you entered 1 (one)"
   L2:Else
      L3:If "[textentry1]" "=" "2"
         Alertbox "test" "you entered 2 (two)"
      L3:Else
         L4:If "[textentry1]" "=" "3"
            Alertbox "test" "you entered 3 (three)"
         L4:Else
            L5:If "[textentry1]" "=" "4"
               Alertbox "test" "you entered 4 (four)"
            L5:Else
               Alertbox "test" "you entered something else"
            L5:EndIf
         L4:EndIf
      L3:Endif
   L2:EndIf
L1:Else
   Alertbox "test" "you didn't enter anything!"
L1:Endif
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dpayer » Thu Apr 26, 2012 8:05 pm

Gaev wrote:David P:

You were missing a couple of EndIf commands ... and for completeness, I added the condition where it was none of "nothing, 1, 2, 3 or 4"


Well darn.... bad logic has struck me again. :)

I *thought* that the IF state was evaluated and if the following statement was true then all other 'else' statements were ignored leaving only the closing endif.

Thanks for the insight Rasl and Gaev.

David P.
User avatar
dpayer
 
Posts: 1384
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest