cheveguerra Member Licensed User Longtime User Oct 16, 2022 #1 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: Copy 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: Copy 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
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: Copy 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: Copy 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 Oct 16, 2022 #2 ? Array B4X: Copy Private theParamsList(m2.Values.Size) As Object o use List to Array B4X: Copy 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
? Array B4X: Copy Private theParamsList(m2.Values.Size) As Object o use List to Array B4X: Copy 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
cheveguerra Member Licensed User Longtime User Oct 16, 2022 #4 TILogistic said: ? Array B4X: Copy Private theParamsList(m2.Values.Size) As Object o use List to Array B4X: Copy 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 Click to expand... 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
TILogistic said: ? Array B4X: Copy Private theParamsList(m2.Values.Size) As Object o use List to Array B4X: Copy 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 Click to expand... 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!!
cheveguerra Member Licensed User Longtime User Oct 16, 2022 #5 TILogistic said: What type is m2.Values? Click to expand... Its a map generated from a json string! Upvote 0