| | |
ISBN 10/13 validation and conversion
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
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,
I thought I'd post them here to see what people think of them.
So,
VB.NET Syntax (Toggle Plain Text)
' Validates an ISBN13 number. If false, it's invalid, else if true, it's valid, Function bVerifySum13(ByRef s As String) As Boolean If Not (s Like "#############" And Mid(s, 1, 3) = "978") Then Return False End If Dim i As Integer = 30 For j As Integer = 4 To 12 Step 2 i += Convert.ToInt32(Mid(s, j - 1, 1)) + (3 * Convert.ToInt32(Mid(s, j, 1))) Next If Not (Mid(s, 13, 1) = ((10 - (i Mod 10)) Mod 10).ToString) Then Return False End If Return True End Function ' Conversion from ISBN13 to ISBN10 Function sConvertN13toN10(ByRef s As String) As String sConvertN13toN10 = Mid(s, 4, 9) Dim i As Integer = 0 For j As Integer = 10 To 2 Step -1 i += (j * Convert.ToInt32(Mid(sConvertN13toN10, (10 - (j - 1)), 1))) Next If (i Mod 11) = 0 Then Return sConvertN13toN10 + "0" End If Dim iCount As Integer = 1 Do Until ((i + iCount) Mod 11) = 0 iCount += 1 Loop If iCount = 10 Then Return sConvertN13toN10 + "X" End If Return sConvertN13toN10 + iCount.ToString End Function ' Validates an ISBN10 number. If false, it's invalid, else if true, it's valid, Function bVerifySum10(ByRef s As String) As Boolean Dim i As Integer = 0 For j = 10 To 2 Step -1 i += ((Convert.ToInt32(Mid(s, (10 - (j - 1)), 1))) * j) Next If (i Mod 11) = 0 And Mid(s, 10, 1) = "0" Then Return True ElseIf Mid(s, 10, 1).ToUpper = "X" Then i += 10 Else i += Convert.ToInt32(Mid(s, 10, 1)) End If If Not ((i Mod 11) = 0) Then Return False End If Return True End Function ' Conversion from ISBN10 to ISBN13 Function sConvertN10toN13(ByRef s As String) As String Dim i As Integer = 30 sConvertN10toN13 = "978" + Mid(s, 1, 9) For j As Integer = 4 To 12 Step 2 i += Convert.ToInt32(Mid(sConvertN10toN13, j - 1, 1)) + (3 * Convert.ToInt32(Mid(sConvertN10toN13, j, 1))) Next Return sConvertN10toN13 + ((10 - (i Mod 10)) Mod 10).ToString End Function
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Registry Permissions
- Next Thread: RenameSongs & tag2file new source available
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 30minutes 2008 access add application array assignment basic binary box button buttons center click code connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dll dosconsolevb.net editvb.net employees error excel exists firewall folder image images isnumericfuntioncall listview login math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan peertopeervideostreaming picturebox plugin port print printing printpreview problem record regex reports" reuse right-to-left save savedialog search serial sorting sql sqldatbase storedprocedure string structures studio temp textbox timer upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml






