Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,542 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,841 people online right now. Registration is fast and FREE... Join Now!




Phone number Code

 
Reply to this topicStart new topic

Phone number Code

kim15m
19 Aug, 2008 - 03:26 AM
Post #1

New D.I.C Head
*

Joined: 18 Aug, 2008
Posts: 1

Hi I need to edit this to suit Zambian phone number system which has 10 digit max and area code 260. I need help and will rely appreciate.
Thank you

vb

Private Sub txtPhone_Validate(Cancel As Boolean)
Dim strTemp As String
Dim strPhone As String
Dim strExtension As String
Dim intResult As Integer

Const DefaultAreaCode = "703"
'
' Remove all the grouping characters for
' now. We'll add them back in later.
'
strTemp = Replace(txtPhone, "(", "")
strTemp = Replace(strTemp, ")", "")
strTemp = Replace(strTemp, "-", "")
strTemp = Replace(strTemp, " ", "")
strTemp = Replace(strTemp, "X", "x")

'
' Break up the digits into the number and
' the extension, if any.
'
intResult = InStr(1, strTemp, "x", vbTextCompare)
If intResult > 0 Then
strExtension = Mid(strTemp, intResult + 1)
strPhone = Left(strTemp, intResult - 1)
Else
strPhone = strTemp
End If

If Left(strPhone, 1) = "1" Then
strPhone = Mid(strPhone, 2)
End If

If Len(strPhone) <> 7 And Len(strPhone) <> 10 Then
MsgBox "Please enter a valid telephone number.", vbExclamation
Cancel = True
Exit Sub
End If

'
' Prepend the default area code
'
If Len(strPhone) = 7 Then
strPhone = DefaultAreaCode & strPhone
End If

'
' Build the new phone number
'
txtPhone = "(" & Left(strPhone, 3) & ") " _
& Mid(strPhone, 4, 3) & "-" _
& Right(strPhone, 4)

'
' Add the extension, if any
'
If strExtension <> "" Then
txtPhone = txtPhone & " x" & strExtension
End If

End Sub


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 10:41PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month