Hello people,
I need to "search" a list for a certain piece of information. If it is found, I will overwrite said record from the list with new information. Otherwise, I add a new record to the list.
I have this code:
From the result of the query, obviously there are repeated records that need to be updated. Well, NEVER find a repeated record !!!! .. Obviously I have something wrongly encoded or misinterpreted.
What could be the reason that it does not work?
Greetings
I need to "search" a list for a certain piece of information. If it is found, I will overwrite said record from the list with new information. Otherwise, I add a new record to the list.
I have this code:
B4X:
ProgressDialogShow("Procesando...ESPERE...")
Dim aRegistros, aCampos As List
Dim aCom() As String
Dim prove = lblProv.Text.SubString2(0,5) As String
Dim depo = lblDeposito.Text.SubString2(0,3) As String
aRegistros.Initialize
aCampos.Initialize
'Consulto el STOCK existente por depositos
Wait For (Main.jConex.GetRecord("select_stock", Null)) Complete (Respuesta As Map)
If Respuesta.Get("Correcto") Then
Dim rs As DBResult
Dim cStk,cArtDep,cCodArt,cNomArt,cCodDep,cCodPro,cUmd As String
Dim nExiste As Double
Dim nID As Int
rs = Respuesta.Get("Datos")
For Each row() As Object In rs.Rows
cStk = row(13) 'STOCKASOC
cArtDep = Main.Func.AgregoCeros(row(0),6) & Main.Func.AgregoCeros(row(5),3) 'CODART+DEPOSITO
cCodArt = Main.Func.AgregoCeros(row(0),6) 'CODART
cNomArt = row(1) 'NOMBRE
cCodDep = row(6) 'NOMDEP
cCodPro = Main.Func.AgregoCeros(row(11),4) & "-" & row(12) 'CODPROV+NOMPROV
cUmd = row(2) 'UMEDSTOCK
nExiste = row(4) 'EXISTENCIA
' nID = -1
nID = aRegistros.IndexOf(cArtDep)
If nID = -1 Then 'Si NO encontro ningun CODART+DEPOSITO, agrego el registro
aCampos.Initialize
aCampos.Add(cArtDep)
aCampos.Add(cCodArt)
aCampos.Add(cNomArt)
aCampos.Add(cUmd)
aCampos.Add(nExiste)
aCampos.Add(0)
aCampos.Add(nExiste)
aCampos.Add(cCodDep)
aCampos.Add(cCodPro)
aCampos.Add(cStk)
aRegistros.Add(aCampos)
Log("Cargo Articulo+Deposito: " & cArtDep)
Else 'Si lo encontró, actualizo existencia
Dim aReg As List
aReg = aRegistros.Get(nID) 'Obtengo el Registro a modificar
aReg.Set(4,aReg.Get(4) + nExiste) 'Agrego existencia a Stk.DEP
aReg.Set(6,aReg.Get(6) + nExiste) 'Agrego existencia a Stk.REAL
aRegistros.Set(nID,aReg) 'Actualizo el registro original con los nuevos valores
Log("Actualizo Articulo+Deposito: " & cArtDep)
End If
Next
Else
ProgressDialogHide
MsgboxAsync(Respuesta.Get("Mensaje"),"")
Return
End If
From the result of the query, obviously there are repeated records that need to be updated. Well, NEVER find a repeated record !!!! .. Obviously I have something wrongly encoded or misinterpreted.
What could be the reason that it does not work?
Greetings