-
Nov 27th, 1999, 03:39 PM
#1
Thread Starter
Hyperactive Member
Hi,
I would like to open up an EXE file into a textbox using this code:
Open "C:\Ascii.exe" For Input As #1
text1.Text = Input(LOF(1), 1)
Close #1
When I try that I get a message "Bad file number or number". What does that mean.
Thanks
-
Nov 27th, 1999, 05:58 PM
#2
Junior Member
I think it has to be opened in Binary mode, but I cant remember the command to get data from a file opened in binary.
Hope this helps.
------------------
Quadrex
webmaster@quadrex.f9.co.uk
Quadrex Programming
-
Nov 28th, 1999, 06:57 AM
#3
PowerPoster
Insert "Binary" between "For" and "Input" on the first line.
It says bad file number, this suggests to me it is the file number playing up here. I notice you use #1 as the file number. Instead, declare a variable (like Dim FileNumber As Variant) and assign it the FreeFile function (FileNumber = FreeFile). Then replace all the #1 you have typed with #FileNumber.
You should now have the following:-
Dim FileNumber As Variant
FileNumber = FreeFile
Open "C:\Ascii.exe" For Binary Input As #FileNumber
Text1.Text = Input(LOF(1), 1)
Close #FileNumber
That should do the trick.
Regards,
------------------
- Chris
chris.kilhams@btinternet.com
If it ain't broke - don't fix it
-
Nov 28th, 1999, 09:40 PM
#4
Humm? Work does it not! No? (My best Yoda impression, Sorry.)
------------------
Matthew Ralston
E-Mail: m.ralston@mediavault.co.uk
ICQ:31422892
Web Sites:The Blue Link My Home Page
[This message has been edited by matthewralston (edited 11-29-1999).]
-
Nov 29th, 1999, 11:42 AM
#5
PowerPoster
what bit doesn't work mr. yoda, supreme jedi commander?
I'm only suggesting it's the file number that's being a problem...I didn't check the rest of Rino's code.
Regards,
------------------
- Chris
chris.kilhams@btinternet.com
If it ain't broke - don't fix it
[This message has been edited by chrisjk (edited 11-29-1999).]
-
Nov 29th, 1999, 02:41 PM
#6
Lively Member
Sorry, my mistake, bad post here, I just deleted it.
I checked again, and it works fine for me when I use "binary" instead of "input"
Steve.
[This message has been edited by SteveS (edited 11-30-1999).]
-
Nov 29th, 1999, 04:07 PM
#7
Hyperactive Member
I get an error in design mode:
Code:
Open "C:\Ascii.exe" For Binary Input As #FileNumber
"Input" is selected...
The error is :
Compile error
Expected: As
-
Nov 29th, 1999, 04:21 PM
#8
Frenzied Member
Do This:
Code:
Dim fnum As Long
Dim strtemp As String
fnum = FreeFile
Open "c:\Ascii.exe" For Binary As fnum
strtemp = Space(LOF(fnum))
Get fnum, , strtemp
Close fnum
the contents of the file are now in strTemp
do waht you want with it!
------------------
Mark Sreeves
Analyst Programmer
Mark.Sreeves@Softlab.co.uk
A BMW Group Company
-
Nov 29th, 1999, 04:44 PM
#9
Member
If you want to READ BINARY you have to insert "Access", i.e.
...
Open strFileName For Binary Access Read As #FileNum
...
AC
-
Nov 29th, 1999, 04:55 PM
#10
Hyperactive Member
Hehehe.... All I seem to get in the crappy textbox is :
MZ
-
Nov 29th, 1999, 04:58 PM
#11
Hyperactive Member
I coud have told you that's all you get.. since a textbox can't really display the binary data (open an exe with notepad and you see what I mean.....)
Why do you want to display the contents of an exe anyway?
-
Nov 29th, 1999, 05:06 PM
#12
Hyperactive Member
Well, it was officially started by Rino_2, I can't give you his motivation....
But sometimes it is handy to edit binary files like you would in a hex-editor....
I've been looking for clean vb-source of a plain hex-editor but haven't realy found one yet.....
This is why I was interested..... Although this post has nothing to do with hex-editing, it is about viewing binaries...
That's all
[This message has been edited by Inhumanoid (edited 11-30-1999).]
-
Nov 29th, 1999, 11:03 PM
#13
Thread Starter
Hyperactive Member
Thank you all, GREAT HELP!!!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|