You misunderstand how variable scope works in B4X, it does not work in the same way as it does in VB.NET or other BASICs. Variables declared anywhere in a procedure may be accessed from anywhere within that procedure. For example, the following will print "Var is 2" to the log in B4A:
Code:
Dim piIndex As Int = 5
If piIndex = 1 Then
Dim piVar As Int
piVar = 1
Else
piVar = 2
End If
Log("Var is " & piVar)
This code would not compile in VB.NET.