Need someone to look over this code for me
Posted
#1
(In Topic #971)
Enthusiast

I could do with a new pair of eyes going over this code for me to see where i have gone wrong as I can not seem to find it
First of I am using this to add item(s) to the DataGridView
Code (gambas)
- ItemToAdd = "Pepsi Max Lime 500ml"
- ItemToadd1 = "£1.80"
- 'Find Item in Grid
- ItemFound = 1
- ItemFound = 0
- iInd = iInd - 1
- iInd = 0
- ProductGrid.Rows.Count += 1
- ProductGrid[ProductGrid.Rows.Count - 1, 1].Text = "4060800306982"
- ProductGrid[ProductGrid.Rows.Count - 1, 2].Text = 1
- ProductGrid[ProductGrid.Rows.Count - 1, 3].Text = 180
and it works fine but if I add another item and then try to add the item again it does not update the existing row it adds a new row
Exanple say I have
4060800306982 2 360
then add
404010011 1 189
and then add another 4060800306982 in stead of showing
4060800306982 3 540
it shows
4060800306982 1 180
<IMG src="https://www.algpos.co.uk/webimage/MSOfferTable_0.png">
</IMG>second Error I seem to get is when i press my "Total" key It calls SubTotalFunction and it works if I have the correct number in the System but it does not work if i have say 3 (example the Pepsi Offer 4060800306982 is 2 for £2.50 so If I had 3 in the scanned Qty field it errors out
<IMG src="https://www.algpos.co.uk/webimage/MSOfferTable_1.png">
</IMG><IMG src="https://www.algpos.co.uk/webimage/MSOfferTable_2.png">
</IMG>this shows how the Promotions should work
If anyone has any recommendations as well as any whys to fix the code and improve it I am all Ears (as we say in the UK)
I have attached the Full Zip of the Mutilsaver project I am working on (I am still using 3.15.2)
Code (gambas)
- ' Gambas module file
- 'get the total from the Product grid (grid1)
- 'Dim TempStore As Integer =
- SubTotal += CInteger(FMain.ProductGrid[iInd, 3].Text)
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, "")
- ProcessOffers
- ' AddMSListTOscreen(SubTotal)
- Case "4060800306982"
- FMain.ProductGrid[iInd, 0].Text = "00001"
- Case "404010011"
- FMain.ProductGrid[iInd, 0].Text = "00002"
- Case "404010022"
- FMain.ProductGrid[iInd, 0].Text = "00002"
- AddAllScannedItemsTogether
- 'apply offer
- ' This will loop though the Scanned products and work out the Got value for each Item
- OfferTotal = (ProductGot * OfferValue)
- FMain.OfferGrid[iInd, 6].Text = OfferTotal
- OfferTotal = (ProductGot * OfferValue)
- FMain.OfferGrid[iInd, 6].Text = OfferTotal
- ' Add all items togther to make a summary
- iLoc = 0
- FMain.OfferGrid[iInd, 5].Text = FMain.ProductGrid[iLoc, 2].Text
- iInd = 0
- FMain.OfferGrid[iInd, 5].Text = ScannedQty
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, " Mutilsavers")
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, " -----------")
- QtyOfferBrack = " " & FMain.OfferGrid[iInd, 4].Text & " @ " & OfferValue
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, FMain.OfferGrid[iInd, 1].Text)
Mulktisaver Test application to work out the kinks before adding the code to the Main Program.
Posted
Guru

it checks if found and makes ItemFound = true.
Then it goes on to check the next item and makes ItemFound = False again.
You should break the loop if found like this..
Then iInd should be correct and not need decrementing.
Posted
Guru

For iInd = 0 To FMain.ProductGrid.Rows.Count - 1 ' Loop thoug the Product groop and add the offer codes to it
then…
If FMain.ProductGrid[iInd, 0].Text = FMain.OfferGrid[iInd, 0].Text Then
If OfferGrid has less items than ProductGrid then it's going to error checking the iInd count
you should also for loop through the OfferGrid with another index var. (i used iInd2)
Like this…
Code (gambas)
- ' Add all items together to make a summary
- iLoc = 0
- FMain.OfferGrid[iInd2, 5].Text = FMain.ProductGrid[iLoc, 2].Text
- iInd = 0
- FMain.OfferGrid[iInd2, 5].Text = ScannedQty
Pedantic notes..
Rows.Max in the same as Rows.Count - 1
No need to write Dim iInt As Integer = 0 by default they already equal 0 so just Dim iInt As Intger does the job
If SomeText = "" , code is faster to write If Not SomeText
Posted
Enthusiast

Thanks so much for spotting the errors I have made
I now have a strange one
When add 2 of the Beans and 2 of the Sausages for some reason when I press the total key it add a 3rd offer
<IMG src="https://www.algpos.co.uk/webimage/Heniz_4.png">
</IMG>This is the update Promotional code I have now
Code (gambas)
- ' Gambas module file
- 'get the total from the Product grid (grid1)
- 'Dim TempStore As Integer =
- SubTotal += CInteger(FMain.ProductGrid[iInd, 3].Text)
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, "")
- ProcessOffers
- AddMSListTOscreen(SubTotal)
- Case "4060800306982"
- FMain.ProductGrid[iInd, 0].Text = "00001"
- Case "404010011"
- FMain.ProductGrid[iInd, 0].Text = "00002"
- Case "404010012"
- FMain.ProductGrid[iInd, 0].Text = "00002"
- AddAllOffersTogether
- 'apply offer
- ' This will loop though the Scanned products and work out the Got value for each Item
- OfferTotal = (TotalQty * OfferValue)
- FMain.OfferGrid[iInd, 6].Text = OfferTotal
- OfferTotal = (TotalQty * OfferValue)
- FMain.OfferGrid[iInd, 6].Text = OfferTotal
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, " Mutilsavers")
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, " -----------")
- QtyOfferBrack = " " & FMain.OfferGrid[iInd, 4].Text & " @ " & OfferValue
- FMain.ListCurrentSale.Add(FMain.ListCurrentSale.Count, FMain.OfferGrid[iInd, 1].Text)
- ' Add all items together to make a summary
- iLoc = 0
- FMain.OfferGrid[iInd2, 5].Text = FMain.ProductGrid[iLoc, 2].Text
- iInd = 0
- FMain.OfferGrid[iInd2, 5].Text = ScannedQty
1 guest and 0 members have just viewed this.



