Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Visual Basic Garbage Values [Solved]
New Posts  All Forums:Forum Nav:

Visual Basic Garbage Values [Solved]

post #1 of 5
Thread Starter 
IsbnTxt Takes a 13 digit integer
CharArr is an array of integers for each digit of IsbnTxt


Below Is the code Code (Click to show)
Dim CharArr(0 To 12) As Integer
Dim counter As Integer
counter = 0
If IsbnTxt.TextLength = 13 Then
For counter = 0 To 12
CharArr(counter) = Convert.ToInt32(IsbnTxt.Text(counter))
Next counter
Outputting IsbnTxt.text reports correct characters but CharArr reports garbage values (IsbnTxt = 9 but CharArr() = 56 wth.gif)
I assume I don't have to initialize CharArr since each Value is getting set to the corresponding IsbnTxt

I think Convert.ToInt32 is messing up confused.gif
Edited by nukefission - 9/15/12 at 7:05am
AzuraChan
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 1055T Asus M4A88TD-V Evo/Usb3 EVGA GTX460 1GB SC + 9800GT Phsyx 2x2GB Corsair 1333MHZ 
Hard DriveOSMonitorPower
6.8TB Total w7 + ubuntu 19" something Seasonic S12II 520W 
Case
modded antec 902 
  hide details  
Reply
AzuraChan
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 1055T Asus M4A88TD-V Evo/Usb3 EVGA GTX460 1GB SC + 9800GT Phsyx 2x2GB Corsair 1333MHZ 
Hard DriveOSMonitorPower
6.8TB Total w7 + ubuntu 19" something Seasonic S12II 520W 
Case
modded antec 902 
  hide details  
Reply
post #2 of 5
ToInt32 is giving you the ASCII code. And I'm not sure why lol. You could subtract 47.

CharArr(counter) = Convert.ToInt32(IsbnTxt.Text(counter)) - 47

Have you tried CInt or CType? Microsoft.VisualBasic.Val will work for sure.
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
post #3 of 5
Thread Starter 
Quote:
Originally Posted by ARandomOWL View Post

ToInt32 is giving you the ASCII code. And I'm not sure why lol. You could subtract 47.
CharArr(counter) = Convert.ToInt32(IsbnTxt.Text(counter)) - 47
Have you tried CInt or CType? Microsoft.VisualBasic.Val will work for sure.
I kinda fixed it by removing CharrArr Completely
But I`l definitly try the -47
AzuraChan
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 1055T Asus M4A88TD-V Evo/Usb3 EVGA GTX460 1GB SC + 9800GT Phsyx 2x2GB Corsair 1333MHZ 
Hard DriveOSMonitorPower
6.8TB Total w7 + ubuntu 19" something Seasonic S12II 520W 
Case
modded antec 902 
  hide details  
Reply
AzuraChan
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 1055T Asus M4A88TD-V Evo/Usb3 EVGA GTX460 1GB SC + 9800GT Phsyx 2x2GB Corsair 1333MHZ 
Hard DriveOSMonitorPower
6.8TB Total w7 + ubuntu 19" something Seasonic S12II 520W 
Case
modded antec 902 
  hide details  
Reply
post #4 of 5
Maybe if you give us the problem as a whole we can find a better solution.
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
Daily
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 2600K @ 4.8GHz, 1.4V Maximus IV Extreme GTX 560 DCII TOP 4x4GB Kingston HyperX 1866MHz CL11 
Hard DriveHard DriveCoolingCooling
Kingston HyperX 3K 120GB Samsung 640GB Thermochill PA120.2 Jingway DB-1 Pump 
CoolingCoolingOSMonitor
2x Kaze Jyuni 1900RPM EK Supreme HF Copper plexi Arch Linux x64 Acer X223HQ 1920x1080 
KeyboardPowerCaseMouse
Microsoft Sidewinder X4 Corsair HX750 Modded Corsair Carbide 500R Logitech M500 
  hide details  
Reply
post #5 of 5
Thread Starter 
FIXED
Old Post Old Post (Click to show)
Okies
Basically This is a function to verify if a 13 digit ISBN number is a valid ISBN
The algorithm gets the digit sum of all the odd digits and the sum of all the even digits *3
The total sum is then mod by 10 and if (10 - remainder = last digit ) then it is valid

Input Number
9780306406157

Correct Odd sum = 27 My Odd sum = 31
Correct Even sum = 66 My Even sum = 66 biggrin.gif
Correct Total sum = 93 My Total sum = 97 wth.gif
Correct Remainder = 3 My Remainder = 7 wth.gif
Code (Click to show)
Function ISBN13() As Boolean
Dim CharArr(0 To 12) As Integer
Dim TotalSum As Integer

Dim counter As Integer
counter = 0

'Gets the Sum Of All The Odd Digits In The ISBN Number'
Dim OddSum As Integer

'Calculates Sum of Even digits'
Dim EvenSum As Integer
EvenSum = 0

'9780306406157'
'1 3 5 7 9 11'

'The loop ignores the first digit for some reason'
OddSum = OddSum + (Microsoft.VisualBasic.Val(IsbnTxt.Text(0)))

For counter = 0 To 11
If (counter Mod 2 = 1) Then
OddSum = OddSum + (Microsoft.VisualBasic.Val(IsbnTxt.Text(counter)))
End If

If ((counter) Mod 2 = 0) Then 'And Not (counter = IsbnTxt.TextLength -)' Then
EvenSum = EvenSum + (Microsoft.VisualBasic.Val(IsbnTxt.Text(counter + 1)) * 3)
End If

Next counter

MessageBox.Show("Odd" + Convert.ToString(OddSum))
MessageBox.Show("Even" + Convert.ToString(EvenSum))

TotalSum = EvenSum + OddSum
MessageBox.Show("Total" + Convert.ToString(TotalSum))


Dim Remainder As Integer
Remainder = TotalSum Mod 10
MessageBox.Show("Remainder" + Convert.ToString(Remainder))


If 10 - Remainder = Convert.ToInt32(IsbnTxt.Text(12)) Then Return True

Exit Function
End Function
Rewrote code in loop

New Code if anybody wants
Somehow it was adding the last digit twice and skipping the first Code (Click to show)
Function ISBN13() As Boolean
If IsbnTxt.TextLength <> 13 Then
IsbnLbl.BackColor = Color.Red
Return False
End If


Dim TotalSum As Integer

Dim counter As Integer
counter = 0

'Gets the Sum Of All The Odd Digits In The ISBN Number'
Dim OddSum As Integer

'Calculates Sum of Even digits'
Dim EvenSum As Integer
EvenSum = 0

'9780306406157'
'1 3 5 7 9 11'

'The loop ignores the first digit for some reason'
OddSum = OddSum + (Microsoft.VisualBasic.Val(IsbnTxt.Text(0)))
OddSum = OddSum - (Microsoft.VisualBasic.Val(IsbnTxt.Text(12)))

For counter = 0 To 11
If (counter Mod 2 = 1) Then
OddSum = OddSum + (Microsoft.VisualBasic.Val(IsbnTxt.Text(counter + 1)))
'MessageBox.Show("Odd counter" + counter.ToString)
'MessageBox.Show("Odd ISBN " + IsbnTxt.Text(counter + 1))
'MessageBox.Show("Odd sum in loop " + OddSum.ToString)
End If

If ((counter) Mod 2 = 0) Then
EvenSum = EvenSum + (Microsoft.VisualBasic.Val(IsbnTxt.Text(counter + 1)) * 3)
'MessageBox.Show("Even counter " + counter.ToString)
'MessageBox.Show("Even ISBN " + IsbnTxt.Text(counter + 1))
End If

Next counter

TotalSum = EvenSum + OddSum

Dim Remainder As Integer
Remainder = TotalSum Mod 10
Dim Checkdigit As Integer
Checkdigit = 10 - Remainder

If Checkdigit.ToString = IsbnTxt.Text(12) Then
IsbnLbl.BackColor = Color.Lime
Return True
End If

If Checkdigit.ToString <> IsbnTxt.Text(12) Then
IsbnLbl.BackColor = Color.Orange
Return False
End If

Exit Function
End Function

Edited by nukefission - 9/15/12 at 7:04am
AzuraChan
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 1055T Asus M4A88TD-V Evo/Usb3 EVGA GTX460 1GB SC + 9800GT Phsyx 2x2GB Corsair 1333MHZ 
Hard DriveOSMonitorPower
6.8TB Total w7 + ubuntu 19" something Seasonic S12II 520W 
Case
modded antec 902 
  hide details  
Reply
AzuraChan
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II x6 1055T Asus M4A88TD-V Evo/Usb3 EVGA GTX460 1GB SC + 9800GT Phsyx 2x2GB Corsair 1333MHZ 
Hard DriveOSMonitorPower
6.8TB Total w7 + ubuntu 19" something Seasonic S12II 520W 
Case
modded antec 902 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Visual Basic Garbage Values [Solved]