Wish Undeclared in Select Case statement

Scantech

Well-Known Member
Licensed User
Longtime User
Check the code below. B4A does not catch "Undeclared Variable" in Case 1. More room for improvements?

Code:
    Dim x As Int
    Select Case x   
        Case 0
            Dim l As List
            l.Initialize
            l.Add("0")
        Case 1
            l.Add(1)
           
    End Select
 
is there any programming language that can catch an undeclared variable?

how can a program do something with a variable that is unknown? it could be a string, it could be a integer, a map, a list, a view,... so why should it work?

sample how it should look:

Code:
Sub catch_me(x As Int)
    Dim l As List
    l.Initialize

    Select x
        Case 0
            Dim new_x As Int = x*25
            l.Add(new_x)
        Case 1
            Dim new_x As Int = x/8
            l.Add(new_x*2)
        Case Else
            l.Clear   
    End Select

    'do here something with l
End Sub

B4A can catch some of it. The following sample below will show "Undeclared Variable" for "l.initialize" in the log.

Code:
    Dim x As Int
  
    Select x
        Case 0
            l.Initialize          
    End Select
 
B4A can catch some of it. The following sample below will show "Undeclared Variable" for "l.initialize" in the log.

no it won't, it will show an error:

l_dec.jpg
 
or do you mean the right top logs just to inform you that there is an error before a compile?
Yes, the Top Right Log.

My first post codes will compile successfully and cause an error when case 1 is triggered.
 
Yes, the Top Right Log.

My first post codes will compile successfully and cause an error when case 1 is triggered.

sorry, i misunderstood you. you are right about that. catching an error while coding is very important.
 
Back
Top