Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21205

Format/Add Spaces to fields of text file, to display consistent columns - list box.

$
0
0
I have added spaces to fields of data pulled from a database, but I'm having problems applying this principal to items read from a text file.
My objective is to add spaces to shorter items, like: "TOM JONES________________"=25, "MAXAMILLION HEIDELBURG___"=25 (space=_)

Using data tables, this worked:
Code:

sTemp = RS.Fields("Groups") & Space(15 - Len(RS.Fields("Groups")))
  sTemp1 = RS.Fields("BitLabel") & Space(17 - Len(RS.Fields("BitLabel")))
List2.AddItem Format(RS.Fields("BitID"), "00") & "    " & sTemp & vbTab & sTemp1 & vbTab & RS.Fields("Time_On")

But in my text array, I don't have specific fields:
Code:

Open "C:\TestFile2.Txt" For Input As FileNumber
    ' read each line in the file, until we've read them all
    Do While Not EOF(FileNumber)
        FormattedData = "" ' clear the temp string
        Line Input #FileNumber, FileData ' read the entire liine from the file
        DataArray = Split(FileData, ",") ' seperate the values based onthe comma
        ' loop through the split up data in the array
        For LoopCounter = 0 To UBound(DataArray)
            ' strip off double quotes, vbTab for new column
            FormattedData = FormattedData & Replace(DataArray(LoopCounter), Chr(34), "") & vbTab
        Next LoopCounter
    lstData.AddItem FormattedData        ' add formatted data to listbox
    Loop
  Close FileNumber

Any suggestions appreciated.

Viewing all articles
Browse latest Browse all 21205


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>