I'm trying, really I am. I don't want to have such a disproportionate amount of posts on VB/VBScript/ASP as opposed to the C#, Java, PHP, Perl, and all the others. But when folks like Ray S send in data validation functions from real, production systems like this, how can I resist?

Public Function CheckIfISBNIsGoodISBNOrNot(PossiblyAnISBN As String)As Variant
'Check if a possible ISBN passed in as PossiblyAnISBN as a string is an ISBN or not an ISBN.
' Creation Date:     March 2000
' Created by:        (CENSORED)
' Last Modified:     Aug 2001
' Modified By:       (CENSORED)
' Version Number:    1.12
' Previous Versions: 1.0, 1.01, 1.04, 1.10
On Error GoTo ErrorChecking
    Dim aValue As String 'string value
    If Len(PossiblyAnISBN) >= 11 Then aValue = "no": GoTo TheEnd
    If Len(PossiblyAnISBN) <= 9 Then aValue = "no": GoTo TheEnd
    If IsNull(PossiblyAnISBN) Then aValue = "no": GoTo TheEnd
    If IsEmpty(PossiblyAnISBN) Then aValue = "no": GoTo TheEnd
    
    CheckIfISBNIsGoodISBNOrNot = "no"
    
    'Check all digits for correctness
    'Digit 1
    Select Case Mid$(PossiblyAnISBN, 1, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 2
    Select Case Mid$(PossiblyAnISBN, 2, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 3
    Select Case Mid$(PossiblyAnISBN, 3, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 4
    Select Case Mid$(PossiblyAnISBN, 4, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 5
    Select Case Mid$(PossiblyAnISBN, 5, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 6
    Select Case Mid$(PossiblyAnISBN, 6, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 7
    Select Case Mid$(PossiblyAnISBN, 7, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 8
    Select Case Mid$(PossiblyAnISBN, 8, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 9
    Select Case Mid$(PossiblyAnISBN, 9, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case Else
            aValue = "no"
    End Select
    'Digit 10 - careful, this might have an "X"
    Select Case Mid$(PossiblyAnISBN, 10, 1)
        Case "0"
            'yup
        Case "1"
            'yup
        Case "2"
            'yup
        Case "3"
            'yup
        Case "4"
            'yup
        Case "5"
            'yup
        Case "6"
            'yup
        Case "7"
            'yup
        Case "8"
            'yup
        Case "9"
            'yup
        Case "X"
            'yup
        Case Else
            aValue = "no"
    End Select
    
    'Check if checkdigit is correct checkdigit for this possibleisbn or not
    ''#todo# -- check checkdigit. Version 1.10 was wrong.
    
    
    If aValue <> "no" Then aValue = "yes" 'if not no then yes
    GoTo TheEnd
    
ErrorChecking:
    'Check errors
    If (aValue <> "no") And (aValue <> "yes") Then Err.Raise 666, ,"There was an error here"
    GoTo TheEnd
TheEnd:
    If (aValue <> "no") And (aValue <> "yes") Then Err.Raise 666, , "I don't know what happened"
    CheckIfISBNIsGoodISBNOrNot = aValue
    Exit Function
End Function

So please, send in your non-BASIC code snippets and the like -- if for no other reason than to make me feel less bad about my language of choice ;-).

 

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!