Android Question 2 or more data in a Variable

dhernandez

Active Member
Licensed User
Longtime User
as I do the following?

I perform a query to a database when ID_CITY field, this field contains 5 records. These 5 records, how do I assign it to a variable?

I use the Loop For ... Next, I do not know how to put the result of the loop with 2 or more records in a variable ...
Somebody help me.
 

dhernandez

Active Member
Licensed User
Longtime User
I did not understand, could you show me an example or give me more details of what he says?

Thank you ..
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

dhernandez

Active Member
Licensed User
Longtime User
Thanks for responding, but I think even I see complicated :(...
Currently I'm doing this to extract the information and assign it to a variable.

B4X:
Sub enviar_click
'''''CONSULTA DESDE SQLITE PARA ASIGNAR LOS RESULTADOS A LAS SIGUIENTES VARIABLES XD
    Dim idcar As String
    Dim tipo As String
    Dim modelo As String
    Dim stock As String
    Dim usuario As String
   
'''''REALIZO LAS CONSULTAS CORRESPONDIENTES. :D
        CARTUCHOS=SQL1.ExecQuery("SELECT * FROM cartuchos")
            For i = 0 To CARTUCHOS.RowCount -1
                CARTUCHOS.Position = i
                       
                idcar=CARTUCHOS.GetString("id_cartucho")
                tipo=CARTUCHOS.GetString("tipo_cartucho")
                modelo=CARTUCHOS.GetString("modelo_cartucho")
                stock=CARTUCHOS.GetInt("stock_cartucho")
                usuario=CARTUCHOS.GetString("usuario_cartucho")
                'Msgbox(CARTUCHOS.GetString("id_cartucho") & " " & CARTUCHOS.GetString("tipo_cartucho") & " " & CARTUCHOS.GetString("modelo_cartucho") & " " & CARTUCHOS.GetInt("stock_cartucho") & " " & CARTUCHOS.GetString("usuario_cartucho"),"Resultados: ")
            Next
                   
''''''''Recojo los datos de las variables y las envío al servidor remoto...
        ExecuteRemoteQuery("INSERT INTO cartuchos(ID_Cartucho, tipo_cartucho, modelo_cartucho, stock_cartucho, usuario_cartucho)VALUES('" & idcar & "','" & tipo & "','" & modelo & "','" & stock & "','" & usuario & "')",MODELO_LISTA)
        TxtID.text=""
        TxtTipo.text=""
        TxtStock.text=""
        TxtModelo.text=""
        TxtUsuario.text=""
        TxtID.RequestFocus
End Sub


The Loop For .. Next, I collected all the information, but the variable to which I am assigned the result accepts me just one ...

I'm stressed about that. guide me


Rgds
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Straight from the new book...
I suggest you get it as a valuable resourse..
Type variables
The Type keyword is used to create your own types or structures. You can use such types to
create simple structures that group some values. However, you can also use it to create
more complex collections. Define a type with the Type keyword:
Sub Process_Globals
Type Person( _
LastName As String, FirstName As String, _
Address As String, City As String _
)
End Sub
We can declare either single variables or arrays of this type:
Dim CurrentUser As Person
Dim User(intUsers) As Person
To access a particular item, we use the variable name and its data item, separated by a
period:
CurrentUser.FirstName = "Wyken"
CurrentUser.LastName = "Seagrave"
If the variable is an array, then the name is followed by the desired index between
parentheses:
User(1).LastName = "Seagrave"
It is possible to assign a typed variable to another variable of the same type:
CurrentUser = User(1)
Declaring Types
Types must be declared in Process_Globals.
A Type cannot be private. Once declared, it is available everywhere (similar to Class
modules).
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Are you looking for something like this?
B4X:
CARTUCHOS=SQL1.ExecQuery("SELECT * FROM cartuchos")
  Dim MyRecCount as Int = CARTUCHOS.RowCount
  Dim MyVar(MyRecCount) as String       'Array holding each record
 
For i = 0 To CARTUCHOS.RowCount -1
CARTUCHOS.Position = i
idcar=CARTUCHOS.GetString("id_cartucho")
tipo=CARTUCHOS.GetString("tipo_cartucho")
modelo=CARTUCHOS.GetString("modelo_cartucho")
stock=CARTUCHOS.GetInt("stock_cartucho")
usuario=CARTUCHOS.GetString("usuario_cartucho")
MyVar(i)= idcar & " " &  tipo & " " &  modelo & " "  & stock & " " & usuario
Next
 
Upvote 0

dhernandez

Active Member
Licensed User
Longtime User
Thank you all for your prompt replies :). Are monsters of programming ...

Mahares, that works well to show all items adapted.
But now I do not know how to send the SQL Remote using this:

B4X:
ExecuteRemoteQuery("INSERT INTO cartuchos(ID_Cartucho, tipo_cartucho, modelo_cartucho, stock_cartucho, usuario_cartucho)VALUES('" & idcar & "','" & tipo & "','" & modelo & "','" & stock & "','" & usuario & "')",MODELO_LISTA)
        TxtID.text=""
        TxtTipo.text=""
        TxtStock.text=""
        TxtModelo.text=""
        TxtUsuario.text=""
        TxtID.RequestFocus

Thank you for your comments, I really appreciate it.
 
Upvote 0
Top