[b][green]'This global declaration ensures that the LIKE statments work correctly[/green]
Option Compare Text[/b]
[b]Sub TransformPhoneData()[/b]
'Change the following line to match the loacation of your
'actual input file
Const cFileInputName As String = "[i]C:\VoicemailReport.txt[/i]"
'These are the tags that will tell the routine where it is in
'the input file
Const cListNumberHeader As String = "LIST NUMBER:"
Const cListNameHeader As String = "LIST NAME:"
Const cNestedSystemListMemebersHeader As String = "NESTED SYSTEM LIST MEMBERS"
Const cMailboxAndNetworkNodeMembers As String = "MAILBOXES AND NETWORK NODE MEMBERS"
'These will be used to process the actual files
Dim blnWriteToFile As Boolean
Dim intFileInput As Integer
Dim intFileNestedSystemListMemebers As Integer
Dim intFileMailboxAndNetworkNodeMembers As Integer
Dim intFileToWrite As Integer
Dim intCharacterPosition As Integer
Dim intField As Integer
Dim strRecord() As String
Dim strLineInput As String
Dim strLinePrint As String
Dim strListNumber As String
Dim strListName As String
'Open the input file
intFileInput = FreeFile
Open [i]cFileInputName[/i] For Input As #intFileInput
'Open the output file that will hold Nested System List Members information
intFileNestedSystemListMemebers = FreeFile
Open "[i]C:\NestedSystemListMemebers.txt[/i]" For Output As #intFileNestedSystemListMemebers
'Open the output file that will hold the Mailbox and Network Node information
intFileMailboxAndNetworkNodeMembers = FreeFile
Open "[i]C:\MailboxAndNetworkNodeMembers.txt[/i]" For Output As #intFileMailboxAndNetworkNodeMembers
'Loop through each line in the Input File and use the following matrix to determine
'what to do with the line
Do
Line Input #intFileInput, strLineInput
'Check for header information
If Trim(strLineInput) = 0 Then
blnWriteToFile = False
ElseIf strLineInput Like "*" & cListNumberHeader & "*" Then
'This line is a header so grab and store the List Number
intCharacterPosition = InStr(strLineInput, cListNumberHeader) + Len(cListNumberHeader) + 1
strListNumber = Trim(Mid(strLineInput, intCharacterPosition))
ElseIf strLineInput Like "*" & cListNameHeader & "*" Then
'This is a header so grab and store the List Name
intCharacterPosition = InStr(strLineInput, cListNameHeader) + Len(cListNameHeader) + 1
strListName = Trim(Mid(strLineInput, intCharacterPosition))
ElseIf strLineInput Like "*" & cNestedSystemListMemebersHeader & "*" Then
'Set the output file pointer for use later
intFileToWrite = intFileNestedSystemListMemebers
blnWriteToFile = False
ElseIf strLineInput Like "*" & cMailboxAndNetworkNodeMembers & "*" Then
'Set the output file pointer for use later
intFileToWrite = intFileMailboxAndNetworkNodeMembers
blnWriteToFile = False
ElseIf strLineInput Like "*TOTAL ENTRIES ON LIST*" Then
'Then end of a section has been reached
blnWriteToFile = False
ElseIf strLineInput Like "*----------------------------------*" Then
'The next line should be data
blnWriteToFile = True
ElseIf blnWriteToFile Then
'No other test was passed so write the data to one of the output files
Select Case intFileToWrite
Case intFileNestedSystemListMemebers
'This Splits the current line to determine the fields
strLinePrint = Chr(34) & strListNumber & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & strListName & Chr(34)
strRecord = Split(strLineInput, " ")
For intField = 0 To UBound(strRecord)
'Since there is an unkown number of spaces, check if there is data
'in the array field before writting
If strRecord(intField) <> "" Then
strLinePrint = strLinePrint & "," & Chr(34) & strRecord(intField) & Chr(34)
End If
Next intField
'Actually write the file
Print #intFileNestedSystemListMemebers, strLinePrint
Case intFileMailboxAndNetworkNodeMembers
'This uses String functions to break up the current line into fields, you may need to adjust
'these to match the actual file format
strLinePrint = Chr(34) & strListNumber & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & strListName & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & Trim(Mid(strLineInput, 5, 6)) & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & Trim(Mid(strLineInput, 11, 11)) & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & Trim(Mid(strLineInput, 23, 20)) & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & Trim(Mid(strLineInput, 44, 9)) & Chr(34)
strLinePrint = strLinePrint & "," & Chr(34) & Trim(Mid(strLineInput, 54)) & Chr(34)
Print #intFileMailboxAndNetworkNodeMembers, strLinePrint
End Select
End If
Loop Until EOF(intFileInput)
'Close all three files
Reset
[b]End Sub[/b]