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

Help needed using VB 6.0, to read .txt, .CVS file types - Oracle

Status
Not open for further replies.

MavrickStl

Programmer
Feb 20, 2001
71
0
0
US
I am trying to use this code to Read .txt or .cvs files via VB6.0 and save the data into variables. And Later I want to import this data into an Oracle database. I have not written the Oracle part yet but my code is having problem reading the data from .csv , .txt files. Urgent help needed. csv and txt files contain multiple lines of data. Mavrick

I am getting this error when I run the code " Compile error:
User_defined type not defined"

Private Sub Command1_Click()
Dim FSO As New FileSystemObject
Dim tsInput As TextStream
Dim varData As Variant

Set tsInput = FSO.OpenTextFile("C:\TransgeneImpact\Test.csv", ForReading)

varData = Split(tsInput.ReadAll, ",")

End Sub
 
Mavrick, you need to add a reference to 'Microsoft Scripting Runtime' in Project \References.
John Whyte
jwhyte@skipton.co.uk
 
Mavrick,

I also forgot to mention, if you want to read through multiple lines, the following code might help:

Code:
' Assume data is like following:
' Mavrick,1,22/02/2001

Dim FSO As New FileSystemObject
Dim tsInput As TextStream
dim varData As Variant

Set tsInput = FSO.OpenTextFile("filename",ForReading)

While Not tsInput.AtEndOfStream
   varData = Split(tsInput.ReadLine,",")
   Debug.Print varData(0) & space(1) & varData(1) & space(1) & varData(2)

  ' Executing this code would display Mavrick 1 22/02/2001   in the immediate window.

Wend

tsInput.Close

Give it a try and see. I think it should work for you. John Whyte
jwhyte@skipton.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top