• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

need help with code

Using vb4 I need help with the following:

In the "General instructions" I have the following code.

Public Function isvalid(ByVal str As String) As Boolean
isvalid = (UCase(str) Like "[a-z][a-z][a-z]#[a-z]##[a-z][a-z]#[a-z]#")
End Function

I am trying to match a pattern for a user entered serial number.
(a-z) = any letter and # = any number. But the letters and the numbers entered MUST match the pattern above.

In the Form command1 is the following:


Private Sub Command1_Click()
abc = Val(Form1.Text1.Text)
If abc = isvalid Then
MsgBox "yea", ib
Else: MsgBox "no", ib
End sub

I get the following error msg even before the prog starts

"ambiguous name detected : isvalid"

Help please
0
hjaycox
Asked:
hjaycox
1 Solution
 
MrNedCommented:
Call the function with a parameter:

If isvalid(abc) Then
0
 
Ryan ChongCommented:
>>"ambiguous name detected : isvalid"
Try find the function 'isvalid', it seems to be appear more that 1 place in your code, leave only 1 function that works for your application.
0
 
DocMCommented:
This syntax seems OK:

Public Function isvalid(ByVal str As String) As Boolean
isvalid = (LCase(str) Like "[a-z][a-z][a-z]#[a-z]##[a-z][a-z]#[a-z]#")
End Function

Private Sub Command1_Click()
abc = Form1.Text1.Text
If isvalid(abc) Then
MsgBox "yea"
Else: MsgBox "no"
End If
End Sub
0
 
hjaycoxAuthor Commented:
DocM

Thank you for your help. With your code, I no longer have that error , But no matter what I type into the text box, correct pattern or not gets me .....Else: MsgBox "no"

Am I missing something????????????
0
 
DocMCommented:
A valid entry would be, for example : abc9d99ef9g9

Public Function isvalid(ByVal str As String) As Boolean
'Expected entry, for example,  abc9d99ef9g9
isvalid = (LCase(str) Like "[a-z][a-z][a-z]#[a-z]##[a-z][a-z]#[a-z]#")
End Function

Private Sub Command1_Click()
abc = Form1.Text1.Text
If isvalid(abc) Then
MsgBox "yea"
Else: MsgBox "no"
End If
End Sub
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now