flynny
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.Fi leSystemOb ject")
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?
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.Fi
If fs.FileExists(getFilename(
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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.
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"
i.e.
i have " D:\test.tRN"
fileName = Trim$(" D:\test.tRN")
ASKER
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.