-
Jan 20th, 2010, 10:39 PM
#1
Thread Starter
Member
-
Jan 20th, 2010, 10:53 PM
#2
Re: really hard
Mid("C:\file.exe", 13, 5)
or maybe 4 instead of 5.
-
Jan 20th, 2010, 10:59 PM
#3
Thread Starter
Member
Re: really hard
but can you explain? it returns me: ack. when I use Mid("C:\file.exe", 13, 4)
-
Jan 20th, 2010, 11:04 PM
#4
PowerPoster
Re: really hard
The data you are reading from *ISN'T* in the format you're trying to read, ASCII is the format the data is in (a char of ASCII value 0-255) while you want hex (two chars of ASCII value 0-15). You need to read two bytes of data in and convert it to hex.
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 20th, 2010, 11:05 PM
#5
Re: really hard
TheMarks
Per Marty's suggestion, please note that the 3rd parameter of
the Mid function specifies the number of characters to be read
from the starting position (which is the 2nd parameter).
So, your Mid("C:\file.exe", 13, 14) will read 14 characters, starting
at character 13.
If you only want byte 13 and byte 14, you could alternatively put
the file into a byte array, say aaBYTE. Then just look at the contents of
aaBYTE(13) and aaBYTE(14). It should be 20 and 03 respectively.
Spoo
-
Jan 20th, 2010, 11:15 PM
#6
Thread Starter
Member
Re: really hard
ok
in the imagem we can see the byte 13 and 14 selected right?
why when I use
image = Mid(globalfile, 13, 4)
msgbox image
I get {L{L ..
look the image:
I just want to get into a text box the numbers : 20 03
just it!
-
Jan 20th, 2010, 11:34 PM
#7
Re: really hard
TheMarks
Probably because hex(20) and hex(03) are non-printable
characters. The Mid function is for character strings, NOT
for reading hex. I think you ought to give the byte array
idea a look-see
Spoo
-
Jan 20th, 2010, 11:35 PM
#8
PowerPoster
Re: really hard
Originally Posted by smUX
The data you are reading from *ISN'T* in the format you're trying to read, ASCII is the format the data is in (a char of ASCII value 0-255) while you want hex (two chars of ASCII value 0-15). You need to read two bytes of data in and convert it to hex.
My last post on the matter (and any thread asking for help from you)...the data you want is stored as an ASCII value and Hex Workshop converts this to HEX format...mid() isn't going to get you HEX values no matter how many times you use it if the file it is taking the data from isn't IN HEX FORMAT
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 20th, 2010, 11:36 PM
#9
Thread Starter
Member
Re: really hard
so HOW can I read the HEX part of the file?
-
Jan 20th, 2010, 11:37 PM
#10
PowerPoster
Re: really hard
Originally Posted by Spoo
TheMarks
Probably because hex(20) and hex(03) are non-printable
characters. The Mid function is for character strings, NOT
for reading hex. I think you ought to give the byte array
idea a look-see
Although technically your idea isn't quite right, if done right it won't return 20 and 03 because it's returning the ASCII value for the byte rather than the two-byte hex value he's looking for :-P
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 20th, 2010, 11:39 PM
#11
PowerPoster
Re: really hard
Originally Posted by TheMarKs
so HOW can I read the HEX part of the file?
There's no such thing as a "HEX part" of the file...the file is in ASCII format, that's how it is, deal with it...and you deal with it by getting the relevant ASCII section and converting it to HEX...
...Or explain what you're trying to actually achieve and maybe someone can suggest a better method that doesn't require hexadecimal data...not me though, I'm outta here.
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 20th, 2010, 11:41 PM
#12
Thread Starter
Member
Re: really hard
Thats a image header, from a gamesystem ..
If i can read the 20 03, I can invert to 03 20 = 800, then I have the width of the image, understand?
in ALL the files I want to read, this information is allocated into byte 13 and 14 .. because that I need to read this bytes ..
-
Jan 21st, 2010, 12:00 AM
#13
PowerPoster
Re: really hard
See, now you've said it, much easier to hopefully help...
Code:
tx = " " & Chr(3) & Chr(32) & " " 'byte 13 and 14 match the info needed
hx = Format$(Hex$(Asc(Mid(tx, 14, 1))), "00") & Format$(Hex$(Asc(Mid(tx, 13, 1))), "00")
tx is just temporary to test it...if you replace the tx in the second line with the variable you're using for the data it'll take the bytes from the relevant part and convert them...
...HOWEVER if you just want to convert the two bytes to the value 800 there's no need to do any hex conversion at all...replace that second line with:
Code:
hx = Asc(Mid(tx, 14, 1)) + (Asc(Mid(tx, 13, 1)) * 256):
and you will find that hx = 800 or whatever the value is supposed to be (assumedly it'll change from file to file)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 21st, 2010, 11:08 AM
#14
Re: really hard
Originally Posted by smUX
Although technically your idea isn't quite right, if done right it won't return 20 and 03 because it's returning the ASCII value for the byte rather than the two-byte hex value he's looking for :-P
Yes.. after I posted, it struck me that I had taken some, ahem,
artistic liberties with my post .. thanks for pointing it out.
Spoo
-
Jan 21st, 2010, 04:31 PM
#15
Thread Starter
Member
Re: really hard
smux, using it:
Dim image As String
image = Asc(Mid(globalfile, 14, 1)) + (Asc(Mid(globalfile, 13, 1)) * 256)
txt1.Text = image
remember: byte 13 = 20, byte 14 = 03
i got txt1.text = 19579
and when use txt1.Text = dec2hex(image) i got 7b4c, and 7b4c isnt the byte 13 and 14 ..
what do you suggest?
Last edited by TheMarKs; Jan 21st, 2010 at 04:38 PM.
-
Jan 21st, 2010, 04:46 PM
#16
Re: really hard
TheMarks, can you upload the txt file you are using. Probably only need the first 30 bytes or so if it is quite large. Also, what value are you expecting?
Note: Hex 20 = decimal 32 & Hex 03 = decimal 3
So depending on how you read it and multiply, you get 2 different values:
32 * 256 + 3 = 8195 whereas 3 * 256 + 32 = 800 & is probably the answer you need
How you got 19579 is beyond me at the moment; this is where a sample text file would be useful.
Edited: 19579 = Hex 4C * 256 + Hex 7B; now I see where you got that; you were reading another section of the file.
Last edited by LaVolpe; Jan 21st, 2010 at 04:51 PM.
-
Jan 21st, 2010, 04:51 PM
#17
Thread Starter
Member
Re: really hard
ye, the files is here http://www.sendspace.com/file/0gjfvy
and look the value is 20 03, if you invert to 03 20, its 800, understand?
Last edited by TheMarKs; Jan 21st, 2010 at 04:55 PM.
-
Jan 21st, 2010, 05:00 PM
#18
Re: really hard
Ok, this was made far much more difficult than necessary.
1. The file you linked us to is in binary format, not ASCII. It is not a text file.
2. If you know the byte offset into the file that you need to read and the number of bytes...
Code:
' integer is 2 bytes, since you only want to read two bytes
' and you know what offsets into the file....
Dim iWidth As Integer, iHeight As Integer
Dim fnr As Integer
fnr = FreeFile
Open yourfilename For Binary As #fnr
Get #fnr, 13, iWidth
Get #fnr, 17, iHeight
Close #fnr
-
Jan 21st, 2010, 05:10 PM
#19
Thread Starter
Member
Re: really hard
woow thank you lavolpe and thanks to every1 who tryies to help me!
the code is working:
Private Sub Form_Load()
' integer is 2 bytes, since you only want to read two bytes
' and you know what offsets into the file....
Dim iWidth As Integer, iHeight As Integer
Dim fnr As Integer
fnr = FreeFile
Open "C:\avatar_back.img" For Binary As #fnr
Get #fnr, 13, iWidth
Get #fnr, 17, iHeight
Text1.Text = iWidth & "x" & iHeight
Close #fnr
End Sub
img:
thank you!
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
|