problems updating a table row

Smee

Well-Known Member
Licensed User
Longtime User
Here we go again

I am trying to test a table to see if a particular product has already been entered if it has then 2 column values are adjusted and the row is updated.
if the product is not in the table then the row is added.

However the code does not work. Could someone explain the error in my logic

StblOrders.Filter("ProductCode='ProductCode'")
If StblOrders.RowCount=1 Then
Qty=StblOrders.Cell("Qty",1)+Qty
StblOrders.Cell("Qty",1)=Qty
StblOrders.Cell("Price",1)=ProdPrice*Qty
Else
StblOrders.AddRow (VanNo,CustCode,TrxNo,ItemNo,Time(Now),Date(Now),ProductCode,ProdPrice,Qty,TrxType,ProdName,ProdPrice*Qty)
End If
StblOrders.Filter("")


i have checked this thread http://www.b4x.com/forum/questions-help-needed/5104-finding-data-table.html

and adapted the code to the following which does work but i would still like to know why the above does not work

Sub ProductExist
Dim i
i=0
If StblOrders.RowCount>0 Then
Do
If ProductCode=StblOrders.Cell("ProductCode",i) Then
Qty1=Qty
Qty=StblOrders.Cell("Qty",i)
Qty=Qty+Qty1
StblOrders.Cell("Qty",i)=Qty
StblOrders.Cell("Price",i)=ProdPrice*Qty
Return True
End If
i=i+1
Loop Until i=StblOrders.RowCount
End If
Return False
End Sub



Thanks

Joe
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Your code must look like this one:

StblOrders.Filter("ProductCode='ProductCode'")
If StblOrders.RowCount=1 Then
Qty=StblOrders.Cell("Qty",0)+Qty
StblOrders.Cell("Qty",0)=Qty
StblOrders.Cell("Price",0)=ProdPrice*Qty
Else
StblOrders.AddRow (VanNo,CustCode,TrxNo,ItemNo,Time(Now),Date(Now),P roductCode,ProdPrice,Qty,TrxType,ProdName,ProdPric e*Qty)
End If
StblOrders.Filter("")

The row index begins with 0 and not with 1 !

Best regards.
 

Smee

Well-Known Member
Licensed User
Longtime User
Thanks Klaus,

i should have twigged to that. I will try it

Joe
 
Top