General discussion

Locked

VB line input statement

By wjhnyc ·
I need an example of using the line input statement in vb6 to read data from a delimited file into an access database.
Thanks

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

VB line input statement

by Lo In reply to VB line input statement

This from VB6 Help, Search, "Line Input" (with edits)

Dim TextLine
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line
<your proc here>
Loop
Close #1 ' Close file.

The above will give you the line. If it has any binary data you will have to do conversion as this is an ASCII input. If the flds can be defined, you do a formatted input defining char & binary data.

I am assuming that "... delimited ..."means something like a CSV, quoted or other separator. Once you get the line into the program you need to process, pulling out each 'field' by searching for the delimiter, extracting the data to a work variable and performing whatever conversion you need. If the input line were:
123456789 123456789 12
"Doe, John",123456.79,...
You would need to check if the string were quoted, the trailing ", extract from position 2 to 11 to get Name (or 2 fields for first, last), extract 13 to 21, convertASCII number to binary number, etc.

Might post 2-3 lines of the delimited file, with and sensative data (name, address, account #, etc.) changed.

I don't have a code sample. Look for string processing functions such as MID$, InStr, etc. Whatyou need to exactly, depends on the input. Also, might consider doing the delimited file as a fixed length field if you can. That makes the processing much easier. If it comes from Excel or some such, it can be saved that way, fields defined as Npositions and data written within the definition (forget the specifics of how, but it's possible, I think we printed it to a disk file). If not Excell or something that will allow, see if whomever creates it will do fixed length (if you have Excel,you can import as delimted and save fixed). Above line fixed field would be:

Name Amt
Doe, John 123456.79
or
LName FName Amt
Doe John 123456.79

Collapse -

VB line input statement

by wjhnyc In reply to VB line input statement

The question was auto-closed by TechRepublic

Collapse -

VB line input statement

by andrew In reply to VB line input statement

Instead of Line Input, you could use the Scripting Runtime library (set a reference to scrrun.dll). This has a nice object model for file manipulation:

Dim oFSO As Scripting.FileSystemObject
Dim oTS As Scripting.TextStream
Dim sLine As String
Dim vLine As Variant, vField As Variant

Set oFSO = New Scripting.FileSystemObject
Set oTS = oFSO.OpenTextFile("c:\filename.csv", ForReading, False)
Do While Not oTS.AtEndOfStream
sLine = oTS.ReadLine
vLine = Split(sLine, ",")
For Each vField In vLine
'update access field here...
Next
Loop
oTS.Close

The example also uses the Split function to parse the line into individual values.

Collapse -

VB line input statement

by wjhnyc In reply to VB line input statement

The question was auto-closed by TechRepublic

Collapse -

VB line input statement

by wjhnyc In reply to VB line input statement

This question was auto closed due to inactivity

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Software Forums