PDA

Click to See Complete Forum and Search --> : Opening an EXE File into a Textbox, Just like opening a text file???


rino_2
Nov 27th, 1999, 02:39 PM
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

Quadrex
Nov 27th, 1999, 04:58 PM
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 (http://www.quadrex.f9.co.uk)

chrisjk
Nov 28th, 1999, 05:57 AM
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, 08:40 PM
Humm? Work does it not! No? :( (My best Yoda impression, Sorry.)

------------------
Matthew Ralston
E-Mail: m.ralston@mediavault.co.uk
ICQ:31422892 (http://195.89.158.103/icq.html)
Web Sites:The Blue Link (http://195.89.158.103) My Home Page (http://mralston.cjb.net)



[This message has been edited by matthewralston (edited 11-29-1999).]

chrisjk
Nov 29th, 1999, 10:42 AM
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).]

SteveS
Nov 29th, 1999, 01:41 PM
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).]

Inhumanoid
Nov 29th, 1999, 03:07 PM
I get an error in design mode:

Open "C:\Ascii.exe" For Binary Input As #FileNumber


"Input" is selected...

The error is :
Compile error
Expected: As

Mark Sreeves
Nov 29th, 1999, 03:21 PM
Do This:

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

Andy Collyer
Nov 29th, 1999, 03:44 PM
If you want to READ BINARY you have to insert "Access", i.e.

...
Open strFileName For Binary Access Read As #FileNum
...

AC

Inhumanoid
Nov 29th, 1999, 03:55 PM
Hehehe.... All I seem to get in the crappy textbox is :

MZ

Crazy D
Nov 29th, 1999, 03:58 PM
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?

Inhumanoid
Nov 29th, 1999, 04:06 PM
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).]

rino_2
Nov 29th, 1999, 10:03 PM
Thank you all, GREAT HELP!!!!!!