You are not logged in.

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

1

Saturday, September 5th 2009, 11:49pm

"else if" problem

Hi,
there seems to be a problem with nested if / elseIf / else if.

Here is my example:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Public Sub Command1_Click()
   Dim a As Boolean = False
   Dim b As Boolean = False
   
   f1 a, b
   f2 a, b
   f3 a, b
End Sub

Private Sub f1(a As Boolean, b As Boolean)
   If a Then
      MsgBox "a"
   Else If b Then     '  note the space between "Else" and "if"
      MsgBox "b"
   End If
   '  missing "End If" not detected by Jabaco
End Sub

Private Sub f2(a As Boolean, b As Boolean)
   If a Then
      MsgBox "a"
   ElseIf b Then
      Msgbox "b"
   End If
End Sub

Private Sub f3(a As Boolean, b As Boolean)
   If a Then
      MsgBox "a"
   Else 
      If b Then
         Msgbox "b"
      End If
   End If
End Sub


And here is the resulting Java code after compilation:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    public void Command1_Click()
    {
        Throwable Err = null;
        boolean a = false;
        boolean b = false;
        f1(a, b);
        f2(a, b);
        f3(a, b);
    }

    private void f1(boolean a, boolean b)
    {
        Throwable Err = null;
        if(a)
        {
            Interaction.MsgBox("a");
        } else
        {
            Interaction.MsgBox("b");
        }
    }

    private void f2(boolean a, boolean b)
    {
        Throwable Err = null;
        if(!a)
        {
            if(b)
            {
                Interaction.MsgBox("b");
            }
        } else
        {
            Interaction.MsgBox("a");
        }
    }

    private void f3(boolean a, boolean b)
    {
        Throwable Err = null;
        if(a)
        {
            Interaction.MsgBox("a");
        } else
        {
            if(b)
                Interaction.MsgBox("b");
        }
    }


Function "f1" contains an error in the source code. The final "end if" is missing (or the space between "Else" and "if" is too much ...).
This is not detected during Jabaco compilation. Jabaco rather compiles a function which ignores the second if variable.

Greetings

A1880

Rate this thread
WoltLab Burning Board