?
Solved

Scan A String

Posted on 2003-03-11
8
Medium Priority
?
208 Views
Last Modified: 2010-05-01


Hi

Does anyone know how can i scan a string/text for Patterns like
phone numbers.

Thanks.


0
Comment
Question by:yanivnachumi1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 8113518
msgbox "this is a phone number 1-800-456-3333" like "*###[-]####*"
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 8113535
The key is the like operator.  You can match more than one separator character in the braces.
0
 

Expert Comment

by:igfp
ID: 8126515
Sure, here's a code that will do the trick. You want to scan a string. Let's say it's a text box called Text1.
First pass that text1 to a string. then analyse each one by one. a command will do this. I don't know what phone numbers you want but american ones are like this? : 1-800-456-3333?? If they are you know they have to have 14 chars. So char number 2, 5 and 9 are "-". We will test this at the begining.

Private Sub cmdVerify_Click()

Dim PhoneNum as string
Dim Temp as String * 1

PhoneNum$ = Text1.text
If Mid(PhoneNum, 2, 1) <> "-" or_
Mid(PhoneNum, 5, 1) <> "-" or_
Mid(PhoneNum, 9, 1) <> "-" or_
len(PhoneNum) <> "15" then
goto error:
Else
End if
' So far we know that there are 15 chars and char 2,
' 5 and 9 are "-", so far so good. Now let's see
' if other chars are numbers!
' For this ww'll use ascii codes from 49 to 57

if Mid(PhoneNum, 5, 1)<"49" and Mid(PhoneNum, 5, 1)>"57" then
goto error:
Else
End if

For i%= 3 to 5
    Temp$ = Mid(AuthorInicial, i%, 1)
    if Temp$ <"49" and Temp$ >"57" Then
     Goto Error:
     Else
Next i%

For i%= 7 to 9
    Temp$ = Mid(AuthorInicial, i%, 1)
    if Temp$ <"49" and Temp$ >"57" Then
     Goto Error:
     Else
Next i%

For i%= 11 to 14
    Temp$ = Mid(AuthorInicial, i%, 1)
    if Temp$ <"49" and Temp$ >"57" Then
     Goto Error:
     Else
Next i%

msgbox "Phone Number Is Correct!"
'Here you should change the msgbox to
'whatever you want to do with the phone
'number (you already know that it's correct)
Exit Sub ' I do this because otherwise it'll
'read the error message anyway!

error:
    msgbox "Phone Number is not correct"
End Sub


Hope this helped!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:igfp
ID: 8127190
instead of 49, 57 use <"9" and > "1" That's what I meant. I forgot to asc so change those values for these and you shall be fine!
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 8128642
igfp:  You could perform the same test using this code:

If PhoneNum Like "#[-]###[-]###[-]####" then
  msgbox "Number is a phone number"
else
  msgbox "Not a phone number"
endif

Adding asterisks to the beginning and end allows you to check if there is a phone number within the string as in my example.  You could also allow spaces for separators, thus:

If PhoneNum Like "#[- ]###[- ]###[- ]####" then
  msgbox "Number is a phone number"
else
  msgbox "Not a phone number"
endif

The like operator is fairly powerful, allowing wildcard matching for multiple or single characters or digits.  It is also very quick both for coding and execution.
0
 

Expert Comment

by:CleanupPing
ID: 9056432
yanivnachumi1:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9097096
yanivnachumi1, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question