Qbasicnews.com

Full Version: Reading a file like a hex editor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

First time poster so please be gentle. Smile

I need to write a program that evaluates the values in a file in hex so I can then modify pieces of it. The attempts I've made opening files in binary have yielded strange results. I think I'm missing something simple.

Anyone have advice or a snippet of code to get me pointed in the right direction?

Thanks!
Welcome to the forum, Seker359 Big Grin

A couple of hints for ya...first of all, make sure you're reading the file by bytes rather than integers. QB has no BYTE type, but STRING * 1 makes a pretty good replacement. You can use ASC to get the value of your byte string. You can use HEX$ to convert that value into a hex version. If the LEN of the hex version isn't 2 places, you can add a 0 to it at the beginning.

I'm gonna post something here but I'm going from memory so don't freak if it's inaccurate...
Code:
DIM inByte AS STRING * 1
.
.
.
GET #fileHandle, , inByte
hexVersion$ = HEX$(ASC(inByte))
IF LEN(hexVersion$) = 1 THEN hexVersion$ = "0" + hexVersion$
Hope that gives you a couple of ideas.
Thanks for the help, that did the trick. It's been a while since I've programmed regularly and it was the string length and the ASC that I was missing when I was messing around with it.

It's amazing how fast you forget this stuff when you don't use it.

Thanks again!