Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP with non-numeric characters 1

Status
Not open for further replies.

gcastillo

Programmer
Jun 9, 2000
127
MX
I need to read a telephone field from a database in a search. The numbers sometimes have things like (01800)123-456. The user types 01800123456 in a form and I need to get the field... I know how to submit the form and how to make my query, but what about the ()-?? Any idea?? Thanks!
 
Gets a little tricky, huh --

Ok, first, you should remove all extraneous characters other than just the numbers... to do this, you need to use the replace function... three times, such as this:

string = (01800)123-456
string = replace(string, ")", "")
string = replace(string, "(", "")
string = replace(string, "-", "")

Now you know what you have:
01800123456
Even if they didn't put in all the extra stuff, no harm, no foul -- now you know.

Then, you need to declare some extra variables to hold the different parts of the string, and then you will concatentate them when you are finished with the wanted format:

dim one, two, three
one = left(string, 5)
two= left(string, 8)
two= right(two, 3)
three = right(string, 3)


then you want to put them all back together with the wanted characters inserted

dim finalString
finalString = "(" & one & ")" & two & "-" & three

easy as 1, 2, 3 (sorry, I couldn't resist)

good luck! :)
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top