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

Flat Data Files - ASCII

Status
Not open for further replies.

CptTom

Programmer
Jul 16, 2001
117
US
How do open a flat text data file, so that I can read and validate its data? Everything I find is how to access MS Access, Foxpro, etc.

Larry
 
Open "C:\whatever.txt" For Input As #1

Do While Not EOF(1)
' Line Input #n reads an entire line.
Line Input #1, inString
' Input #n reads until it finds a comma.
Input #1, xName, xCity, xAmount
Loop
Close #1

- vbMax :)
 
These are 'Fixed Width' Fields. Now what?
 
Use a user defined type to read/write fixed width text from a file.

Private Type MyTable
Field1 As String * 5 'defines width of each field
Field2 As String * 10
Field3 As String * 12
End Type

Private Sub ReadFile()
Dim FileNum as Long
Dim OneRec as MyTable

FileNum = FreeFile
Open "C:\Whatever.TXT" For Random As #FileNum & _
Len = Len(OneRec)
Do Until EOF(FileNum)
Get #FileNum, ,OneRec
Validate (OneRec.Field1)
Validate (OneRec.Field2) 'and so forth
Loop
Close #FileNum
End Sub

To Write the data to the file, Open the file using the same open statement but use "Put" instead of "Get"

Adam
 
Is it also possible to view the data? Do I need to use VISDATA? The strings run less than 100 characters in length * the number of records.
 
Depending on how you want to view it, the easiest would be to put a text box on a form, then append the text to the text box inside the do..while loop. If it's just for debugging probably having it open (or a copy of) in notepad would be fine.
 
yeah, but they would want the columns separating the fields. I thought about creating something along the line of a data screen so they could scroll through the data.
 
You can use a listbox and format to space out the columns. You could also use a flexgrid control.
-Chris (Consultant / Software Engineer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top