Problem to Convert a Javascript GTIN calculate function to VB.net
-
Hello, I am not able to convert this function to VB code.... This is the javascript function to get the last digit of a GTIN number:
factor = 3;
sum = 0;var gNum = '1234564020233'
for (index = gNum; index > 0; --index) { sum = sum + gNum.substring(index - 1, index) \* factor; factor = 4 - factor; } cc = ((1000 - sum) % 10); result = gNum + cc; }
I have the problem to deal with the substring function. Anyone can help?
-
Hello, I am not able to convert this function to VB code.... This is the javascript function to get the last digit of a GTIN number:
factor = 3;
sum = 0;var gNum = '1234564020233'
for (index = gNum; index > 0; --index) { sum = sum + gNum.substring(index - 1, index) \* factor; factor = 4 - factor; } cc = ((1000 - sum) % 10); result = gNum + cc; }
I have the problem to deal with the substring function. Anyone can help?
OK, JavaScript substring returns the string enclosed by the start and ending values. In your case that would be
index - 1
, andindex
. It appears that index starts out with the length of the string in gNum and goes backwards by -1 with each iteration.A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Hello, I am not able to convert this function to VB code.... This is the javascript function to get the last digit of a GTIN number:
factor = 3;
sum = 0;var gNum = '1234564020233'
for (index = gNum; index > 0; --index) { sum = sum + gNum.substring(index - 1, index) \* factor; factor = 4 - factor; } cc = ((1000 - sum) % 10); result = gNum + cc; }
I have the problem to deal with the substring function. Anyone can help?
factor = 3
sum = 0
Dim gNum As String = "1234564020233"For index = gNum To 1 Step -1
sum = sum + gNum.Substring(index - 1, index - (index - 1)) * factor
factor = 4 - factor
Next indexcc = ((1000 - sum) Mod 10)
result = gNum + ccDavid Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
-
factor = 3
sum = 0
Dim gNum As String = "1234564020233"For index = gNum To 1 Step -1
sum = sum + gNum.Substring(index - 1, index - (index - 1)) * factor
factor = 4 - factor
Next indexcc = ((1000 - sum) Mod 10)
result = gNum + ccDavid Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com
Hi David, I got this error: System.Data.Index' is not accessible in this context because it is 'Private'.
-
Hi David, I got this error: System.Data.Index' is not accessible in this context because it is 'Private'.
It must be due to 'index' not being declared. Try:
For index As Integer = gNum To 1 Step -1
David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com