Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Problem with vb code please help
Closed Thread
Old 08-05-2004, 06:21 AM   #1 (permalink)
 
Wizard Techie

Join Date: Mar 2004

Posts: 3,784

waynejkruse10

Default Problem with vb code please help

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
__________________
Core 2 Duo E6400, DFI Infinity 975X/G, 2x 512mb DDR2 667mhz, Albatron 7900gt, WD 200gb SATA, Samsung DVD-RW, Silverstone ST-50EF 500w PSU.
waynejkruse10 is offline  
Old 08-06-2004, 10:42 PM   #2 (permalink)
 
Newb Techie

Join Date: Jun 2004

Posts: 22

lexor

Default

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
Quote:

Dim fnum As Integer
Dim nvar as String
fnum = FreeFile()
Open "a.txt" For Input As #fnum
nvar = Input(LOF(fnum), fnum)
msgbox nvar

lexor is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On