ISBN 10/13 validation and conversion

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 19
Reputation: NightCrawler03X is an unknown quantity at this point 
Solved Threads: 0
NightCrawler03X's Avatar
NightCrawler03X NightCrawler03X is offline Offline
Newbie Poster

ISBN 10/13 validation and conversion

 
0
  #1
Jan 24th, 2009
Awhile ago I wrote some functions to convert from isbn10 to isbn13, or from isbn13 to isbn10; and subsequently some function to validate isbn 10/13 numbers.

I thought I'd post them here to see what people think of them.

So,
  1. ' Validates an ISBN13 number. If false, it's invalid, else if true, it's valid,
  2. Function bVerifySum13(ByRef s As String) As Boolean
  3. If Not (s Like "#############" And Mid(s, 1, 3) = "978") Then
  4. Return False
  5. End If
  6. Dim i As Integer = 30
  7. For j As Integer = 4 To 12 Step 2
  8. i += Convert.ToInt32(Mid(s, j - 1, 1)) + (3 * Convert.ToInt32(Mid(s, j, 1)))
  9. Next
  10. If Not (Mid(s, 13, 1) = ((10 - (i Mod 10)) Mod 10).ToString) Then
  11. Return False
  12. End If
  13. Return True
  14. End Function
  15.  
  16. ' Conversion from ISBN13 to ISBN10
  17. Function sConvertN13toN10(ByRef s As String) As String
  18. sConvertN13toN10 = Mid(s, 4, 9)
  19. Dim i As Integer = 0
  20. For j As Integer = 10 To 2 Step -1
  21. i += (j * Convert.ToInt32(Mid(sConvertN13toN10, (10 - (j - 1)), 1)))
  22. Next
  23. If (i Mod 11) = 0 Then
  24. Return sConvertN13toN10 + "0"
  25. End If
  26. Dim iCount As Integer = 1
  27. Do Until ((i + iCount) Mod 11) = 0
  28. iCount += 1
  29. Loop
  30. If iCount = 10 Then
  31. Return sConvertN13toN10 + "X"
  32. End If
  33. Return sConvertN13toN10 + iCount.ToString
  34. End Function
  35.  
  36. ' Validates an ISBN10 number. If false, it's invalid, else if true, it's valid,
  37. Function bVerifySum10(ByRef s As String) As Boolean
  38. Dim i As Integer = 0
  39. For j = 10 To 2 Step -1
  40. i += ((Convert.ToInt32(Mid(s, (10 - (j - 1)), 1))) * j)
  41. Next
  42. If (i Mod 11) = 0 And Mid(s, 10, 1) = "0" Then
  43. Return True
  44. ElseIf Mid(s, 10, 1).ToUpper = "X" Then
  45. i += 10
  46. Else
  47. i += Convert.ToInt32(Mid(s, 10, 1))
  48. End If
  49. If Not ((i Mod 11) = 0) Then
  50. Return False
  51. End If
  52. Return True
  53. End Function
  54.  
  55. ' Conversion from ISBN10 to ISBN13
  56. Function sConvertN10toN13(ByRef s As String) As String
  57. Dim i As Integer = 30
  58. sConvertN10toN13 = "978" + Mid(s, 1, 9)
  59. For j As Integer = 4 To 12 Step 2
  60. i += Convert.ToInt32(Mid(sConvertN10toN13, j - 1, 1)) + (3 * Convert.ToInt32(Mid(sConvertN10toN13, j, 1)))
  61. Next
  62. Return sConvertN10toN13 + ((10 - (i Mod 10)) Mod 10).ToString
  63. End Function
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: ISBN 10/13 validation and conversion

 
0
  #2
Jan 25th, 2009
Thanks for sharing
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC