[Solved] Advice 0n converting this VB code
Posted
#1
(In Topic #640)
Enthusiast

I Hope someone can help me
I am trying to convert this code from Visual BASIC to Gambas
the code works out the check digit for a barcode number using Mod10CheckDigit (Based on https://www.freevbcode.com/ShowCode.asp?ID=1035)
Code
Dim i As Integer = 0
Dim TotalOdd As Integer = 0
Dim TotalEven As Integer = 0
Dim Total As Integer = 0
Barcode = Trim(Barcode)
'get odd numbers
For i = 1 To Len(Barcode) Step 2
TotalOdd = TotalOdd + CInt(Mid(Barcode, i, 1))
Next
TotalOdd = TotalOdd * 3
'get even numbers
i = 0
For i = 2 To Len(Barcode) Step 2
TotalEven = TotalEven + CInt(Mid(Barcode, i, 1))
Next
Total = TotalOdd + TotalEven
Dim BarcodeLocal As Integer = 10 - IIf(Right(Total, 1) = 0, 10, Right(Total, 1))
BarcodeNumberInHouse = Barcode & BarcodeLocal
but when the app runs I get on the following Line
Dim BarcodeLocal As Integer = 10 - IIf(Right(Total, 1) = 0, 10, Right(Total, 1))
Type Mismatch: wanted string, got integer instead in Global:274
I hope someone can advice me
Posted
Enthusiast

as you dim an integer you may should do something like -> val(right(total,1))
Posted
Enthusiast

PJBlack said
as far as i can see at fast looking … you compare a char (right(Total, 1)) with an integer as you been told b y the interpreter![]()
as you dim an integer you may should do something like -> val(right(total,1))
Hi PJ,
I tried that but I am still getting the same error. (Im struggling with this in Gambas hell I even struggled with this in VB and VB.net lol)
Posted
Enthusiast

Posted
Guru

Posted
Enthusiast

Code (gambas)
- '' Modulo10 Prüfziffernberchnung für u.a. EAN13 Barcodes
- iTotal = ((iTotalOdd * 3) + iTotalEven) % 10
Posted
Guru

EDIT
I have looked further into this and if you are trying to create codes for EAN barcodes your code needs to calculate the odd and even numbers from right to left see here. The following code seems to work for EAN barcodes used on books.
Code (gambas)
Posted
Enthusiast

cogier said
Which type of barcode are you intending to use? If it is 128B then I have put the necessary code on the Farm called Own_Barcode.
EDIT
I have looked further into this and if you are trying to create codes for EAN barcodes your code needs to calculate the odd and even numbers from right to left see here. The following code seems to work for EAN barcodes used on books.Code (gambas)
Thank-you cogier that works perfectly with both EAN8 and EAN13 barcode numbers
1 guest and 0 members have just viewed this.



