Duplicate Variable not detected during compile

Mike Maurice

Member
Licensed User
Longtime User
Sub Globals or Process_Globals

Dim Button1 As Button
Dim Button1 As Button

No error.

This also applies to other types: Int, Byte, etc.

Ver 2.70.
 

agraham

Expert
Licensed User
Longtime User
Sometimes you NEED to re-Dim a variable to get a new instance of an object after you have used the previous one
B4X:
For I = 0 to 9
  Dim b as Button ' make a new Button instance
  b.Initialize("SomeEventName")
  ... ' do something with it like add it to a View
Next
If the Dim b As Button was outside the For loop you would be using the same Button all the time which would probably not be what was intended.
 
Top