Android Question Generate JRDC cmd.parameters dinamically

cheveguerra

Member
Licensed User
Longtime User
Hi everybody,

I am trying to generate a "cmd.Parameters" for a "reqManager.ExecuteQuery" dynamically, but I don't know how to generate an array as object!!

If I try:
B4X:
        Private theParamsList As List
        theParamsList.Initialize
        For Each myVal As String In m2.Values 'Here we get the values
            theParamsList.Add(myVal)
        Next
        cmd.Parameters = theParamsList
        reqManager.ExecuteCommand(cmd , theQuery)

I get a "List cannot be converted to object" error, but if I dim theParamsList as "object", then I cannot add items to it:

B4X:
            Private theParamsList() As Object
            Dim cont As Int = 0
            For Each myVal As String In m2.Values 'Here we get the values
                theParamsList(cont)=myVal
                cont=cont+1
            Next

But then I get an "index out of bound for lenght 0" because the object does not have elements and I cannot add to it.

So, how can I generate an array as object dynamically?

Best regards
 

TILogistic

Expert
Licensed User
Longtime User
? Array
B4X:
Private theParamsList(m2.Values.Size) As Object

o use List to Array
B4X:
Public Sub ListToArray(inList As List) As Object()
    Dim OutArray(inList.Size) As Object
    For i = 0 To inList.Size - 1
        OutArray(i) = inList.Get(i)
    Next
    Return OutArray
End Sub
 
Upvote 0

cheveguerra

Member
Licensed User
Longtime User
? Array
B4X:
Private theParamsList(m2.Values.Size) As Object

o use List to Array
B4X:
Public Sub ListToArray(inList As List) As Object()
    Dim OutArray(inList.Size) As Object
    For i = 0 To inList.Size - 1
        OutArray(i) = inList.Get(i)
    Next
    Return OutArray
End Sub

And then it is so EASY after being so HARD šŸ˜

So the first one creates the object with the size I need and then I can add items.

And the second one converts the list directly to an array!!

THANKS A LOT!!!

That solved my problem!!
 
Upvote 0
Top