Can you use a variable without declaring?

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I have little time using B4A and I found it strange to note that variables are used that have not been declared, for example in this code is used DButils variable "i", is this normal or is something special?
Thanks and regards.

B4X:
Sub CreateTable(SQL As SQL, TableName As String, FieldsAndTypes As Map, PrimaryKey As String)
   Dim sb As StringBuilder
   sb.Initialize
   sb.Append("(")
   For i = 0 To FieldsAndTypes.Size - 1
      Dim field, ftype As String
      field = FieldsAndTypes.GetKeyAt(i)
      ftype = FieldsAndTypes.GetValueAt(i)
      If i > 0 Then sb.Append(", ")
      sb.Append("[").Append(field).Append("] ").Append(ftype)
      If field = PrimaryKey Then sb.Append(" PRIMARY KEY")
   Next
   sb.Append(")")
   Dim query As String
   query = "CREATE TABLE IF NOT EXISTS [" & TableName & "] " & sb.ToString
   Log("CreateTable: " & query)
   SQL.ExecNonQuery(query)
End Sub
 

bluejay

Active Member
Licensed User
Longtime User
In the B4A documentation it says:

For
Syntax:
For variable = value1 To value2 [Step interval]
...
Next
If the iterator variable was not declared before it will be of type Int.

bluejay
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thank you all.
I find it very curious to use undeclared variables.
Greetings.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…