Problem with vb code please help

Status
Not open for further replies.

waynejkruse10

Fully Optimized
Messages
3,782
i want to read from a file called a.txt into a string and i use this code

Private Sub Form_Load()
Dim read As String
Dim filename As String
filename = "C:\a.txt"
read = Space(FileLen(filename))
Open filename For Input As #1
Get #1, 1, read
Close #1
MsgBox (read)
End Sub

but it comes up with an error 54 bad file mode
does anyone know whats wrong with it
thanks
wayne
 
You can not use the Get method with the Input mode of the open command. The Get method is being use if you open a file as binary.
Instead try this one
Dim fnum As Integer
Dim nvar as String
fnum = FreeFile()
Open "a.txt" For Input As #fnum
nvar = Input(LOF(fnum), fnum)
msgbox nvar
 
Status
Not open for further replies.
Back
Top Bottom