943,950 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 2396
  • VB.NET RSS
Jan 24th, 2009
0

ISBN 10/13 validation and conversion

Expand Post »
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,
VB.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NightCrawler03X is offline Offline
16 posts
since Jan 2009
Jan 25th, 2009
0

Re: ISBN 10/13 validation and conversion

Thanks for sharing
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Registry Permissions
Next Thread in VB.NET Forum Timeline: RenameSongs & tag2file new source available





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC