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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

maybe someone can help me, i have a

Status
Not open for further replies.

robman70

Technical User
Aug 6, 2002
90
maybe someone can help me, i have a text field that a phone number is entered into, after the phone number is entered it is formatted to look like 713 555-1212, after that i want to format it to remove the spaces and the dash, the code below removes the space but deletes the dash and everything after, so the number ends up 713555 and no 1212, is there a better way to do this or something im missing?

Private Sub cmdSolect_Click()
Dim intPhoneField
If txtCustPhone.Text = "" Then
MsgBox "Phone number field is blank ", vbCritical, "Scratchy Pad"
txtCustPhone.SetFocus
Exit Sub
End If
intPhoneField = Val(txtCustPhone.Text)
intPhoneField = Replace(intPhoneField, "-", "")
'intPhoneField = Replace(intPhoneField, " ", "")
txtCustPhone.Text = intPhoneField
End Sub

thanks for any help
 
Dim strPhone as String
strPhone = Replace$(txtCustPhone.Text," ","")
strPhone = Replace(strPhone,"-","")
' Now convert however but you have 10 digits which will not foit in an Integer or a Long Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
If you are formatting it for display purposes, arent u taking oo much of a trouble to format it back to 'numeric only', and the saving and then formatting it again when u take it outta the db and display? why can't u save it as it is as a string? All the Best
Praveen Menon
pcmin@rediffmail.com
 

'to get the individual no. and then join it
-------------------------------------------
Dim lclCountryCode, lclStateCode, lclPhoneNo, lclStr
lclPhoneNo = Mid(Trim(txtCustPhone.Text), InStr(1, Trim(txtCustPhone.Text), "-") + 1, Len(Trim(txtCustPhone.Text)))

lclStr = Mid(Trim(txtCustPhone.Text), 1, InStr(1, Trim(txtCustPhone.Text), "-") - 1)

lclStateCode = Mid(Trim(lclStr), InStr(1, Trim(txtCustPhone.Text), " ") + 1, Len(Trim(lclStr)))

lclCountryCode = Mid(Trim(txtCustPhone.Text), 1, InStr(1, Trim(txtCustPhone.Text), " ") - 1)

'lclPhoneNo = lclCountryCode + " " + lclStateCode + " " + lclPhoneNo
lclPhoneNo = lclCountryCode + lclStateCode + lclPhoneNo

'if you want to remove the dash and just to have the Number
----------------------------------------------------------

Dim intphonefield
intphonefield = Replace(txtCustPhone.Text, "-", " ")
txtCustPhone.Text = intphonefield
 
Phone "numbers" are almost NEVER stored as (numeric) values. You should review the guidelines for the determiniation of data types. The generic rule is only use Numeric type(s) where the VALUE is to be used in a calculation. I'm not aware of any calculation which would be useful involving phone numbers as operands.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Hi, HTH
in your making of the string you can do something like this.

Dim strint As Long
strint = CLng(Mid(MaskEdBox1.Text, 1, 3) + Mid(MaskEdBox1.Text, 4, 3))

Result will be 713555

Remembering that though the Mask is seen by the user it is not stored as it is seen.

Again HTH
AntonV
 
Your original line
intPhoneField = Val(txtCustPhone.Text)
will cause leading zero numbers to be dropped.
This can cause problems on international calls as 001 will convert to 1.
JohnYingling sent you an answer which I like as it is clean and easy. If its complicated, its wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top