Sub aaaaa
Dim aNumbers() As int
End Sub
Sub bbbbb
Dim iAmount as int = DBconex.ExecQuerySingleResult("select count(id) from tbSome")
aNumbers.SetLength( iAmount ) ' <--- Can you do something similar?
End Sub
In that case you better use a List type, as it grows dinamicaly when you add itens to it and you do not need to care with array dimensions.
However, if your intention is just to use an array of fixed dimension, you can do something like
but ensure that iAmount is a valid value...You probably do not want to dimension an array with 0 elements
[P.S. no, it does not work.
You could use a List o a Map (better solution) or:
MyModule:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public aNumbers() As Int
End Sub
Public Sub SetNumbersCount(N As Int)
Dim aNumbers(N) As Int
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public aNumbers() As Int
End Sub
Public Sub SetNumbersCount(N As Int)
Dim aNumbers(N) As Int
End Sub
You need to declare the variables in your globales-module. As public.
THEN you can use them in other modules or activities.
You can NOT dim new variables in globales from your activity... The dim must be in your module
But you should use a List or a Map (I prefer Maps; you can consider them as a kind of matrix, two-dimensional arrays, with the advantage of being able to identify each element by a name (or an object!), in addition to what I write below).
Using a List instead of an array of Int, you can:
B4X:
Public lstNumbers As List : lstNumbers.Initialize
' "resize" the List automatically
lstNumbers.Add(123)
' Insert a List (or array) inside the List
Dim InsertAt As Int = 2
lstNumbers.AddAllAt(InsertAt, Array As Int(1,2,3))
' Search for a value in the List (value can be an object)
Dim IndexOf5 As Int = lstNumbers.IndexOf(5)
' Remove an element
lstNumbers.RemoveAt(3)
' Set a value for an element
lstNumbers.Set(2, 567)
' Sort the List
lstNumbers.Sort(True)