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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV issue

Status
Not open for further replies.

techu4

Technical User
Jun 27, 2005
32
GB
Hi,

I receive a csv file from a client that needs to have the data split into text boxes on a form. I have had this working for ages and now the client has changed the format of the csv file.

it used to come with multiple rows of data and each row was seperated by commas.

Now it comes as a single line of data and has vblf defining were the rows are and then each of the rows are seperated by commas again.

here is the code that was working but does not like the vblf now.

Code:
strPath = sPath
strFile = HoldName
strFile = Dir(strPath & strFile)

Do While strFile <> ""
    Open strPath & strFile For Input As #1
    
    On Error GoTo errorhandler
Do
   ReDim Preserve RowData(x)
   Line Input #1, strData
   RowData(x) = strData
   strData = vbNullString
   x = x + 1
   Loop Until EOF(1)

UpDown1.Max = UBound(RowData)
UpDown1.Min = LBound(RowData) + 2

Dim ColData() As String
ColData = Split(RowData(2), ",")
For i = 0 To UBound(ColData)
    Text1(i).Text = ColData(i)
Next i
Close #1
    strFile = Dir
Loop
Text2.Text = recordNo + 1
Text3.Text = UBound(RowData) - 1
Exit Sub
errorhandler:
MsgBox "Failed to open record. Please check the report file from Welcome.", vbCritical, "Critcal Error"
End Sub


Function populate(iIndex As Integer)
On Error Resume Next
Dim ColData() As String
ColData = Split(RowData(iIndex), ",")
For i = 0 To UBound(ColData)
    Text1(i).Text = ColData(i)
Next i
End Function

Could anyone help me please as i can't seem to be able to work out what needs changing.

regards

 
Change...

Do
ReDim Preserve RowData(x)
Line Input #1, strData
RowData(x) = strData
strData = vbNullString
x = x + 1
Loop Until EOF(1)

To...

Code:
Line Input #1, strData
RowData = Split(strData, vbLf)

Since all of the data is returned on the first row, you won't need to loop. The split function will put the data in to the array for you all in 1 shot.

Hope this helps.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top