Link to home
Start Free TrialLog in
Avatar of Sabrin
Sabrin

asked on

Semicolon Delimited Text

hello,
I have this nice module that works on Tab Delimited Text
but Im having problems trying to convert it to Semicolon Delimited Text
can someone please help me?


Option Explicit

  Public FSO As FileSystemObject
  Public TS As TextStream
  Public lItem As ListItem
  Public J, I As Integer          'counters
  Public isEditSaved As Boolean   'edit boolean
  Public isChangeMade As Boolean  'saved boolean
 
  Dim tabLine() As String         'string to hold line of tab delimited text


Public Sub LoadFile(mPath As String, LVW As ListView)
  'clear any previous items in the listView
  LVW.ListItems.Clear
  Set FSO = New FileSystemObject
  'open the file for reading
  Set TS = FSO.OpenTextFile(mPath, ForReading, False)
  'split the line into a string array
  tabLine = Split(TS.ReadLine, vbTab)
  'cycle through the array and add the column headers
  For J = 0 To UBound(tabLine)
    LVW.ColumnHeaders.Add , , tabLine(J)
  Next J
  'cycle through the rest of the file to add the items
  While Not TS.AtEndOfStream
    tabLine = Split(TS.ReadLine, vbTab)
    Set lItem = LVW.ListItems.Add(, , tabLine(0))
    For J = 1 To UBound(tabLine)
      lItem.ListSubItems.Add , , tabLine(J)
    Next J
  Wend
  'close and clean up
  TS.Close
  Set TS = Nothing
  Set FSO = Nothing
End Sub

Public Sub SaveFile(mPath As String, LVW As ListView, useHeaders As Boolean)
  Set FSO = New FileSystemObject
  Set TS = FSO.OpenTextFile(mPath, ForWriting, True)
  'if saving headers, get them from the column header text
  'and write them to the file first
  If useHeaders Then
    For J = 1 To LVW.ColumnHeaders.Count
      TS.Write LVW.ColumnHeaders(J).Text & vbTab
    Next J
    TS.WriteLine
  End If
  'write all items to the file
  For J = 1 To LVW.ListItems.Count
    TS.Write LVW.ListItems(J).Text & vbTab
    For I = 1 To LVW.ListItems(J).ListSubItems.Count
      TS.Write LVW.ListItems(J).ListSubItems(I).Text & vbTab
    Next I
    TS.WriteLine
  Next J
  'close the file and clean up
  TS.Close
  Set TS = Nothing
  Set FSO = Nothing
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Raynard7
Raynard7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial