If ... else

Discussion in 'Questions (Windows Mobile)' started by colin9876, Nov 18, 2007.

  1. colin9876

    colin9876 Active Member Licensed User

    Really Basic BASIC question

    why doesnt this code work
    if n=0 then msgbox("No")
    else msgbox("yes")

    The if part works on its own but ive somehow got the else condition wrong because it doesnt work when I add that part?

    Also if I want to do 2 things after an if how do I combine them so it does both on condition of that if?
    e.g if n=0 then msgbox("No")
    and x=1
     
  2. petrbury

    petrbury Member Licensed User

    Hi,
    try

    If n=0 Then
    Msgbox("No")
    Else
    Msgbox("yes")
    End If

    it should work.

    The second question :

    If condition Then
    action1
    action2
    .
    .
    actionx
    End If

    Regards
    Petr
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    There are two syntaxes:
    Code:
    If n = 0 then msgbox("No"else msgbox("yes")   'Single line
    or:
    Code:
    If n=0 then
     
    msgbox("no")
     ...
    else if n = 1 then
     ...
    else if ... then
     ...
    else
     ...
    end if
     
  4. colin9876

    colin9876 Active Member Licensed User

    Thanks - very helpful.
    I see it was because I had the IF ELSE over two lines that it didnt work - much appreciated
     
Loading...