Results 1 to 6 of 6

Thread: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

  1. #1

    Thread Starter
    Member AndreiMhz's Avatar
    Join Date
    Dec 2010
    Location
    Romania
    Posts
    62

    VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

    This code will enable you to encode binary files to Intel HEX format, using I8HEX (8 Byte), I16HEX (16 Byte) or I32HEX (32 Byte).

    It also has a separate Checksum calculation function based on something i found here on the forum.

    To encode a HEX file, simply add this module to you project and call the function like so :

    Code:
    Bin2HexFile App.Path & "\printerimage.bmp", App.Path & "\hello.hex"
    To verify the HEX files created, google for HEX2BIN (freeware). I had initially attached it in the ZIP, but forum policies here advise against this kind of practice, so it's better to download a converter yourself.

    This is useful when uploading binary files (bitmaps, wave files, etc.) to microcontrollers, memories or other types of electronic devices. Maximum file size to encode is about 64KiB, as there are a total of 65535 addresses available.
    If you have 16 bytes / address, divide 65535/16 and you get ~4096 addresses of 16 bytes each.

    Intermec PD42 printers make use of this format to receive pictures, for example...

    Use this code however you wish, i claim absolutely NO copyright over it.
    Enjoy !

    PS: This works for VB4 - VB6 and is optimised for speed, not for small and efficient code. You may find some optimisations are possible....
    Attached Files Attached Files
    Last edited by AndreiMhz; Dec 27th, 2010 at 11:55 AM. Reason: Removed EXE File
    If this post solved your problem, please mark your thread as [SOLVED] and rate the post. It's a good way to show appreciation.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

    Quote Originally Posted by AndreiMhz View Post
    i also included a HEX2BIN decoder
    And, although we thank you for your CodeBank submission, per this CodeBank policy, I have edited your attachment and removed it.

    We welcome and appreciate all entries into our Codebank, but ask that source code only be included with anything attached.

    Thank you.

  3. #3

    Thread Starter
    Member AndreiMhz's Avatar
    Join Date
    Dec 2010
    Location
    Romania
    Posts
    62

    Wink Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

    Do as thou wisheth
    If this post solved your problem, please mark your thread as [SOLVED] and rate the post. It's a good way to show appreciation.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

    It is a short code, not a fast one.

    A quick summary for issues regarding speed include use of the variant version of Mid instead of string version Mid$, Val and conversion of numeric data to string to numeric, ReDim Preserve in a tight loop for each new item, and finally IIf which is one of the worst performing language structures in VB as it is very much just a regular function that can be custom written in VB and it'll be faster – even as a Variant version. The biggest issue is that because it is just a regular function it runs both True and False cases no matter what is the result, so it always does work that doesn't need to be done.

    But. I guess this procedure always deals so small amount of data that it won't really matter to make it faster.

  5. #5

    Thread Starter
    Member AndreiMhz's Avatar
    Join Date
    Dec 2010
    Location
    Romania
    Posts
    62

    Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

    [QUOTE=Merri;3933867]It is a short code, not a fast one.
    QUOTE]

    You are right... it's not the fastest one that could be done, but it's not the shortest one either. A lot of improvements can be made, in both directions : be it size or be it speed.



    But, for 64Kbyte files... as you said. Maybe it's not worth the trouble
    If this post solved your problem, please mark your thread as [SOLVED] and rate the post. It's a good way to show appreciation.

  6. #6
    New Member
    Join Date
    Oct 2012
    Posts
    1

    Re: VB4 / VB5 / VB6 - Binary file to Intel HEX Encoder (pretty fast one,too)

    Hello,

    Firstly, I really thank you!
    I'm a newbie about vb and trying to solve a problem.

    I am using the code and i got an error below:

    "By(q) = <Subscript out of range>"

    How can I fix this?

    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
  •  



Click Here to Expand Forum to Full Width