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!

strip and add

Status
Not open for further replies.

ciarra41

Technical User
Sep 11, 2006
116
US
I am trying to stip ( or - from numbers, like
Myfield:(111)222-3333 then to Newfield:111222333. But sometime I need
to add them back like 1112223333 then to (111)222-3333.

thanks

 



WHY?

Either its just a NUMBER with a MASK or its TEXT.

Which are they?

Skip,

[glasses] [red][/red]
[tongue]
 
I am sorry, their text, and sometime numbers because I'm loading them from a mainframe. I would use the mask but it can be bothersome. Let's just say text if it would be easier for you.

Thanks
 



That's not the question.

What does the TABLE DESIGN say that the field data type is?

Skip,

[glasses] [red][/red]
[tongue]
 
Here's a small class that I use for formatting phone numbers that may be of some use to you.
Code:
Option Explicit

Private mvarAreaCode                As String
Private mvarNumber                  As String
Private mvarParsedNumber            As String

Public Property Let Number(ByVal vData As String)
    Dim n                           As Integer
    Dim X                           As String
    
    mvarNumber = vData
    mvarParsedNumber = ""
    For n = 1 To Len(vData)
        X = Mid$(vData, n, 1)
        If X >= "0" And X <= "9" Then mvarParsedNumber = mvarParsedNumber & X
    Next

End Property

Public Property Get Number() As String

    If Len(mvarParsedNumber) = 7 Then
        Number = Left$(mvarParsedNumber, 3) & "-" & Right$(mvarParsedNumber, 4)
    ElseIf Len(mvarParsedNumber) = 10 Then
        Number = Mid$(mvarParsedNumber, 4, 3) & "-" & Right$(mvarParsedNumber, 4)
    ElseIf Len(mvarParsedNumber) = 11 And Left$(mvarParsedNumber, 1) = "1" Then
        Number = Mid$(mvarParsedNumber, 5, 3) & "-" & Right$(mvarParsedNumber, 4)
    Else
        Number = mvarNumber
    End If

End Property


Public Property Get FullNumber() As String
    If Len(Me.AreaCode) > 0 Then
        FullNumber = "(" & Me.AreaCode & ") " & Me.Number
    Else
        FullNumber = Me.Number
    End If
End Property

Public Property Get ParsedNumber() As String
    If Len(Me.Number) = 0 Then
        ParsedNumber = ""
    Else
        ParsedNumber = Me.AreaCode & Left$(Me.Number, 3) & Right(Me.Number, 4)
    End If
End Property



Public Property Let AreaCode(ByVal vData As String)
    mvarAreaCode = vData
End Property


Public Property Get AreaCode() As String

    AreaCode = mvarAreaCode

    If Len(Trim(mvarAreaCode)) = 0 Then
        If Len(Trim(mvarParsedNumber)) = 10 Then
            AreaCode = Left$(Trim(mvarParsedNumber), 3)
        ElseIf Len(Trim(mvarParsedNumber)) = 11 And Left$(Trim(mvarParsedNumber), 1) = "1" Then
            AreaCode = Mid$(Trim(mvarParsedNumber), 2, 3)
        Else
            AreaCode = ""
        End If
    End If

End Property
If you set the Number Property to 123-555-6543 (for example) then the property Number will return it as 555-6543. The property FullNumber will return (123) 555-6543 and the property ParsedNumber will return 1235556543.

It will return the input string unchanged if the value you set as Number is not a legitimate phone number which is defined as
[li]Seven Numeric digits OR [/li]
[li]Ten Numeric Digits OR[/li]
[li]Eleven Numeric Digits beginning with 1[/li]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top