|
-
Apr 20th, 2006, 02:12 PM
#1
Thread Starter
Hyperactive Member
Doing Calculations on Integers in an array
I am working on verifying Vin numbers and cannot figure out how to take my converted array, which is the result of the first sub and multiple each one of the numbers to set of weighted values.
For instance I have taken the VIN shown in the string below and converted it to this 41312348565041183, which is correct. Now I need to take each number in that string and multiply it like this:
1st Position * 8
2nd position * 7
3rd position * 6
4th position * 5
Would be
4 * 8 = 32
1 * 7 = 7
3 * 6 = 18
1 * 5 = 5
and so on. Here is the code I have so far. My trouble is in the CalcVin Sub.
VB Code:
Private Sub ConvertVin()
Dim strVin As String = "4A3AK34Y5WE041183"
Dim arrVin(16) As Char
arrVin = strVin.ToCharArray
Dim c As Char
For Each c In arrVin
txtResults.Text += CStr(VinAlphaConvert(c))
Next c
End Sub
Private Sub CalcVin()
Dim strConVin As String = txtResults.Text
Dim arrVin(16) As Integer
arrVin(0) += arrVin(0) * 8
MessageBox.Show(CStr(arrVin(0)))
'Dim c As Char
'arrVin(0) += CChar(CStr(CInt(Val(c)) * 8))
' I need to take each of the 17 integers and
' multiply them by a weight factor like this
'1st = 8 10th = 9
'2nd = 7 11th = 8
'3rd = 6 12th = 7
'4th = 5 13th = 6
'5th = 4 14th = 5
'6th = 3 15th = 4
'7th = 2 16th = 3
'8th = 10 17th = 2
'9th = check digit
-
Apr 21st, 2006, 05:58 AM
#2
Re: Doing Calculations on Integers in an array
You could just loop through, having a select case on the value 0 - 16, then changing each case like that...
VB Code:
For I As Integer = 0 To 16 Step 1
Select Case I
Case 0, 10
arrVin(I) = arrVin(I) * 8
'etc
End Select
Next I
Last edited by gigemboy; Apr 21st, 2006 at 06:02 AM.
-
Apr 21st, 2006, 09:00 AM
#3
Thread Starter
Hyperactive Member
Re: Doing Calculations on Integers in an array
Thanks gigemboy. I am still having a lot of problems with this so I going to take one step back and make sure I am explaining this correctly. So before I get to that part I need to get the string of numbers from the textbox to become numbers and not text characters.
Once I get them into numbers and then weight each number according to its position in the array I need to add them together to get a total sum. So to begin how do I get each number from the array so they are treated as numbers and not chars?
Here is some pseudocode to help describe my task.
Characters in the array = 1 2 3 (from a textbox)
Character in the position 1 gets converted to an number and multiplied by 5
Character in the position 2 gets converted to an number and multiplied by 10
Character in the position 3 gets converted to an number and multiplied by 15
1 * 5 = 5
2 * 10 = 20
3 * 15 = 45
Add all weighted numbers together 5+20+45 = 70
Am I even on the right track or is there a better way to do this?
Last edited by FastEddie; Apr 21st, 2006 at 09:07 AM.
-
Apr 21st, 2006, 10:16 AM
#4
Re: Doing Calculations on Integers in an array
Well in your string above ("4A3AK34Y5WE041183"), the second character position is a letter, not a number (as well as several other letters in the string). So what values are used for those?
-
Apr 21st, 2006, 10:37 AM
#5
Thread Starter
Hyperactive Member
Re: Doing Calculations on Integers in an array
The first function turns any letters into numbers and leaves the numbers as they are. Here is the sub and the function:
VB Code:
Private Sub ConvertVin()
Dim strVin As String = "4A3AK34Y5WE041183"
Dim arrVin(16) As Char
arrVin = strVin.ToCharArray
Dim c As Char
For Each c In arrVin
txtResults.Text += CStr(VinAlphaConvert(c))
Next c
End Sub
Public Function VinAlphaConvert(ByVal str As String) As Integer
Dim int As Integer
Select Case str
Case "A" : int = 1
Case "B" : int = 2
Case "C" : int = 3
Case "D" : int = 4
Case "E" : int = 5
Case "F" : int = 6
Case "G" : int = 7
Case "H" : int = 8
Case "J" : int = 1
Case "K" : int = 2
Case "M" : int = 3
Case "N" : int = 4
Case "P" : int = 7
Case "R" : int = 9
Case "S" : int = 2
Case "T" : int = 3
Case "U" : int = 4
Case "V" : int = 5
Case "W" : int = 6
Case "X" : int = 7
Case "Y" : int = 8
Case "Z" : int = 9
Case Else
int = CInt(str)
End Select
Return int
End Function
That works find and turns 4A3AK34Y5WE041183 into 41312348565041183. Now I just to take each one of those numbers indivudualy and multiply them in the way I mentioned above.
Maybe this will help if you look at this page VIN NUMBER CONTENT REQUIREMENT. About half way down the page there are 4 steps that explain exactly what I am trying to do.
-
Apr 21st, 2006, 11:41 AM
#6
Re: Doing Calculations on Integers in an array
You might want to just keep the return value of the alphaconvert in a string instead of an integer (or since you have that like it is, just use the .ToString method on the integer return value in order to loop through all characters so you dont have to change the function), that way you can just loop through each character of the number string, replacing as necessary, like below...
VB Code:
Dim MyString As String = "41312348565041183"
Dim ReturnString As String 'string to hold conversion
For Each Number As Char In MyString
Select Case Number
Case Is = "1"c
'append new value onto the string
ReturnString &= (1 * 8).ToString
'etc
End Select
Next
MessageBox.Show(ReturnString)
'now just convert ReturnString to an integer
Last edited by gigemboy; Apr 21st, 2006 at 11:46 AM.
-
Apr 21st, 2006, 11:52 AM
#7
Frenzied Member
Re: Doing Calculations on Integers in an array
There might be some errors with that website,...
They failed to mention that the first digit of 9 means Brazil.
Also, the 2nd letter V is also for Volkswagen, as explained here.
I have owned numerous Volkswagens (hence my handle), and i know for a fact that my VINs have been:
3VW... = Mexico
9VW... = Brazil
WVW... = Germany
VIN's were standardized at seventeen characters in 1981. So any car made before that might not decode properly.
The 9th character check digit explained.
~Peter

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|