Domino 9 und frühere Versionen > ND6: Entwicklung
Telefonnummern Parsen
bikerboy:
Ich freue mich über die rege Beteiligung,
@Axel genauso sollte es sein, man einfach eine Nummer reingeben und parst sie dann ins richtige Format, zwar ist es in dem Konkreten Beipspiel fast immer passend, aber halt nicht immer. Und kann ich den Code ja auch in anderen Anwendungen zur Anwendung kommen lassen.(Dürfte im Sinne von Bernhardt sein )
bikerboy:
hier ein erster Versuch :
--- Code: ---Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim Proc As NotesDocument
Set Proc = ws.CurrentDocument.Document
Dim Phone List As String
Dim findArray(9) As String
Dim replaceArray(9) As String
Dim strArea As String
Dim strCountry As String
Dim strLine As String
Dim strExtension As String
Dim strCheckArea As String
Dim strCheckLine As String
Dim strCheckNewArea As String
Dim strCheckNewLine As String
Dim strCheckCountry As String
Dim strCheckNewCountry As String
Dim intLengthComplete As Integer
Dim intLengthLastPart As Integer
findArray(0) = " "
findArray(1) = "/"
findArray(2) = "\"
findArray(3) = "-"
findArray(4) = "("
findArray(5) = ")"
findArray(6) = "|"
findArray(7) = "~"
findArray(8) = "#"
findArray(9) = "'"
replaceArray(0) = " "
replaceArray(1) = " "
replaceArray(2) = " "
replaceArray(3) = " "
replaceArray(4) = " "
replaceArray(5) = " "
replaceArray(6) = " "
replaceArray(7) = " "
replaceArray(8) = " "
replaceArray(9) = " "
tmpPhone = Replace(Proc.ParserFieldComplete(0),findArray , replaceArray)
DelimCount = 1
Erase Phone
If tmpPhone <> "" Then
varPhone = Split(tmpPhone, " ")
If Ubound(varPhone) = 0 Then
strCountry = Left(varPhone(0),1)
If strCountry = "+" Then
Proc.ParserFieldCountry= Left(varPhone(0),3)
Else
Proc.ParserFieldCountry= Left(varPhone(0),1)
End If
intLenthComplete = Len(varPhone(0))
intLengthLastPart = Len(Proc.ParserFieldCountry(0))
varPhone(0) = Right(varPhone(0),(intLenthComplete - intLengthLastPart))
strArea = Left(varPhone(0),4)
Proc.ParserFieldArea = strArea
intLengthLastPart = Len(Proc.ParserFieldArea(0))
intLenthComplete = Len(varPhone(0))
varPhone(0) = Right(varPhone(0),(intLenthComplete - intLengthLastPart))
strExtensionCheck = Right(varPhone(0),1)
If strExtensionCheck = "0" Then
Proc.ParserFieldLine = Left(varPhone(0),Len(varPhone(0))-1)
Proc.ParserFieldExtension = Right(varPhone(0),1)
Else
Proc.ParserFieldLine = varPhone(0)
End If
Elseif Ubound(varPhone) = 1 Then
Call Proc.ReplaceItemValue("ParserFieldCountry",varPhone(0))
Call Proc.ReplaceItemValue("ParserFieldArea", Left(varPhone(1),4))
Call Proc.ReplaceItemValue("ParserFieldLine",Right(varPhone(1),Len(varPhone(1))-4))
If Right(Proc.ParserFieldLine(0),1) = "0" Then
Call Proc.ReplaceItemValue("ParserFieldExtension",Right(Proc.ParserFieldLine(0),1))
Call Proc.ReplaceItemValue("ParserFieldLine",Left(Proc.ParserFieldLine(0),Len(Proc.ParserFieldLine(0))-1))
End If
Elseif Ubound(varPhone) = 2 Then
Call Proc.ReplaceItemValue("ParserFieldCountry",varPhone(0))
Call Proc.ReplaceItemValue("ParserFieldArea",varPhone(1))
Call Proc.ReplaceItemValue("ParserFieldLine",varPhone(2))
If Right(Proc.ParserFieldLine(0),1) = "0" Then
Call Proc.ReplaceItemValue("ParserFieldExtension",Right(Proc.ParserFieldLine(0),1))
Call Proc.ReplaceItemValue("ParserFieldLine",Left(Proc.ParserFieldLine(0),Len(Proc.ParserFieldLine(0))-1))
End If
Elseif Ubound(varPhone) = 3 Then
Call Proc.ReplaceItemValue("ParserFieldCountry",varPhone(0))
Call Proc.ReplaceItemValue("ParserFieldArea",varPhone(1))
Call Proc.ReplaceItemValue("ParserFieldLine",varPhone(2))
Call Proc.ReplaceItemValue("ParserFieldExtension",varPhone(3))
Elseif Ubound(varPhone) = 4 Then
Call Proc.ReplaceItemValue("ParserFieldCountry",varPhone(0))
Call Proc.ReplaceItemValue("ParserFieldArea",varPhone(1)+ varPhone(2))
Call Proc.ReplaceItemValue("ParserFieldLine",varPhone(3))
Call Proc.ReplaceItemValue("ParserFieldExtension",varPhone(4))
Elseif Ubound(varPhone) = 5 Then
Call Proc.ReplaceItemValue("ParserFieldCountry",varPhone(0))
Call Proc.ReplaceItemValue("ParserFieldArea",varPhone(1) + varPhone(2))
Call Proc.ReplaceItemValue("ParserFieldLine",varPhone(3) + varPhone(4))
Call Proc.ReplaceItemValue("ParserFieldExtension",varPhone(5))
End If
End If
' Validieren der Daten
'Prüfen der Vorwahl
strCheckArea = Proc.ParserFieldArea(0)
strCheckLine = Proc.parserFieldLine(0)
If Len(strCheckArea) > 4 Then
strCheckNewArea = Left(strCheckArea,4)
strCheckNewLine = Right(strCheckArea,(Len(strCheckArea)-Len(strCheckNewArea))) +strCheckLine
If Left(strCheckNewLine,1) = "0" Then
strCheckNewLine = Right(strCheckNewArea,1) + strCheckNewLine
strCheckNewArea = Left(strCheckNewArea,Len(strCheckNewArea)-1)
If Left(strCheckNewLine,1) = "0" Then
strCheckNewLine = Right(strCheckNewArea,1) + strCheckNewLine
strCheckNewArea = Left(strCheckNewArea,Len(strCheckNewArea)-1)
If Left(strCheckNewLine,1) = "0" Then
strCheckNewLine = Right(strCheckNewArea,1) + strCheckNewLine
strCheckNewArea = Left(strCheckNewArea,Len(strCheckNewArea)-1)
If Left(strCheckNewLine,1) = "0" Then
strCheckNewLine = Right(strCheckNewArea,1) + strCheckNewLine
strCheckNewArea = Left(strCheckNewArea,Len(strCheckNewArea)-1)
End If
End If
End If
End If
Proc.ParserFieldArea = strCheckNewArea
Proc.ParserFieldLine = strCheckNewLine
End If
PhoneNumber = Proc.ParserFieldCountry(0) + " " +Proc.ParserFieldArea(0) + " / "+ Proc.ParserFieldLine(0) + " - " +Proc.ParserFieldExtension(0)
Call Proc.Replaceitemvalue("ParserFieldComplete", PhoneNumber)
End Sub
--- Ende Code ---
guesswho:
sorry Robert, würd dir gern helfen, aber mir ist grad übel :P
flaite:
Wochenende schaff ichs vielleicht.
Ist ok, wenn das im Sinne der Aufgabenstellung ist.
Aber eigentlich sollte man dafür echt regex nehmen.
Ist schon sehr viel code im Verhältnis zur Aufgabe.
Parsen kann beliebig komplex werden.
bikerboy:
--- Zitat von: guesswho am 16.01.08 - 18:48:50 ---sorry Robert, würd dir gern helfen, aber mir ist grad übel :P
--- Ende Zitat ---
Warum überl ist der Code so beschissen ?
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln