AndyCapp
Apr 6th, 2000, 09:55 PM
Hello,
I have received the following code to verify that an e-mail address is correctly typed into a text box to be passed into an Access 97 table.
The code runs fine in VB 6 but I also need it to run in VB 5. When I run the code in VB 5 I get the following error message: "Complie Error" "Sub or Function Not Defined"
then when I click 'debug' the following piece of code is highlighted within the module code: InStrRev
I would greatly appreciate any help, links or code as to why this is happennig or even a way of getting around it within VB 5. The code I am using is below...
Thanks,
Andy.............
Function checkValidEmail(theAddress) As Boolean
'http://www.4guysfromrolla.com/webtech/051999-1.shtml
On Error GoTo ExitFalse
' checks for a valid email
' returns false for invalid addresses
Dim atCnt
checkValidEmail = True
' chk length
If Len(theAddress) < 5 Then
' a@b.c should be the shortest an
' address could be
checkValidEmail = False
' chk format
' has at least one "@"
ElseIf InStr(theAddress, "@") = 0 Then
checkValidEmail = False
' has at least one "."
ElseIf InStr(theAddress, ".") = 0 Then
checkValidEmail = False
' has no more than 3 chars after last "."
ElseIf Len(theAddress) - InStrRev(theAddress, ".") > 3 Then
checkValidEmail = False
' has no "_" after the "@"
ElseIf InStr(theAddress, "_") <> 0 And _
InStrRev(theAddress, "_") > InStrRev(theAddress, "@") Then
checkValidEmail = False
Else
' has only one "@"
atCnt = 0
For i = 1 To Len(theAddress)
If Mid(theAddress, i, 1) = "@" Then
atCnt = atCnt + 1
End If
Next
If atCnt > 1 Then
checkValidEmail = False
End If
' chk each char for validity
For i = 1 To Len(theAddress)
If Not IsNumeric(Mid(theAddress, i, 1)) And _
(LCase(Mid(theAddress, i, 1)) < "a" Or _
LCase(Mid(theAddress, i, 1)) > "z") And _
Mid(theAddress, i, 1) <> "_" And _
Mid(theAddress, i, 1) <> "." And _
Mid(theAddress, i, 1) <> "@" And _
Mid(theAddress, i, 1) <> "-" Then
checkValidEmail = False
End If
Next
End If
Exit Function
ExitFalse:
checkValidEmail = False
Exit Function
End Function
[Edited by AndyCapp on 04-07-2000 at 11:10 AM]
I have received the following code to verify that an e-mail address is correctly typed into a text box to be passed into an Access 97 table.
The code runs fine in VB 6 but I also need it to run in VB 5. When I run the code in VB 5 I get the following error message: "Complie Error" "Sub or Function Not Defined"
then when I click 'debug' the following piece of code is highlighted within the module code: InStrRev
I would greatly appreciate any help, links or code as to why this is happennig or even a way of getting around it within VB 5. The code I am using is below...
Thanks,
Andy.............
Function checkValidEmail(theAddress) As Boolean
'http://www.4guysfromrolla.com/webtech/051999-1.shtml
On Error GoTo ExitFalse
' checks for a valid email
' returns false for invalid addresses
Dim atCnt
checkValidEmail = True
' chk length
If Len(theAddress) < 5 Then
' a@b.c should be the shortest an
' address could be
checkValidEmail = False
' chk format
' has at least one "@"
ElseIf InStr(theAddress, "@") = 0 Then
checkValidEmail = False
' has at least one "."
ElseIf InStr(theAddress, ".") = 0 Then
checkValidEmail = False
' has no more than 3 chars after last "."
ElseIf Len(theAddress) - InStrRev(theAddress, ".") > 3 Then
checkValidEmail = False
' has no "_" after the "@"
ElseIf InStr(theAddress, "_") <> 0 And _
InStrRev(theAddress, "_") > InStrRev(theAddress, "@") Then
checkValidEmail = False
Else
' has only one "@"
atCnt = 0
For i = 1 To Len(theAddress)
If Mid(theAddress, i, 1) = "@" Then
atCnt = atCnt + 1
End If
Next
If atCnt > 1 Then
checkValidEmail = False
End If
' chk each char for validity
For i = 1 To Len(theAddress)
If Not IsNumeric(Mid(theAddress, i, 1)) And _
(LCase(Mid(theAddress, i, 1)) < "a" Or _
LCase(Mid(theAddress, i, 1)) > "z") And _
Mid(theAddress, i, 1) <> "_" And _
Mid(theAddress, i, 1) <> "." And _
Mid(theAddress, i, 1) <> "@" And _
Mid(theAddress, i, 1) <> "-" Then
checkValidEmail = False
End If
Next
End If
Exit Function
ExitFalse:
checkValidEmail = False
Exit Function
End Function
[Edited by AndyCapp on 04-07-2000 at 11:10 AM]