Link to home
Start Free TrialLog in
Avatar of flynny
flynnyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

help with fileio in vb6

Hi,

i want to read a file in in vb. i'm a little new to the syntaxt so hope you can help.

basically i want to open and read a file one line at a time. Each line that is read in is structure i.e. chars 0-15 are description 16-20 user code etc. How can i do this?

I have created an additional module with the following code however it doesn't seem to be findint he file. Am i doing something wrong?

Public Function OpenFile(f As String) As Boolean

Set fs = CreateObject("Scripting.FileSystemObject")

If fs.FileExists(getFilename()) Then
    Open getFilename() For Random As #1 Len = 200
    fopen = True
    OpenFile = True
End If

fopen = False
OpenFile = False

End Function

Public Function ReadLine() As String

If fopen Then
    Line Input #1, sBuffer
    ReadLine = sBuffer
End If

ReadLine = Null

End Function

where i read the value for the file in from the command line. (this is working as the string is correct that is being passed ( c:\test.txt ) )

any ideas?
ASKER CERTIFIED SOLUTION
Avatar of peetm
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flynny

ASKER

hi i've tried this and i still get a runtime error 424 object requied when trying to GetFile(<my String>)

the text i have read in is D:\TEST.tRN and this is file is present in the D:\ root and the string does read this. is there something i'm doing wrong here??

Many Thanks,

Matt.
What's the actual structure of the file - if it's text, can you post up a few lines of it.  If it's binary email it.
Avatar of flynny

ASKER

hi i've found the prob there a trailing space before the string due to how i read do you know if there is any trim methods i can use to remove this.

i.e.
i have " D:\test.tRN"
fileName = Trim$(" D:\test.tRN")