Results 1 to 8 of 8

Thread: [VB6] Escer, Hexer Classes and EscBuddy Tool

Threaded View

  1. #1

    Thread Starter
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    [VB6] Escer, Hexer Classes and EscBuddy Tool

    Title

    Escer, Hexer, and EscBuddy

    Description

    Two VB6 Classes and a utility program intended to make it easier to have String literals in your program that contain binary data and/or Unicode characters. The emphasis here is on the Escer Class.

    An example might be the need to use this Armenian text in your VB6 progam:

    Code:
    strVar = "Աեցեհի իմ լավ ?ւղիե լավարար"
    Since VB6 only allows ANSI text in a String this only works if your current locale and codepage is set to an appropriate Armenian one, and even then there might be conversion problems because converting from ANSI to Unicode and back is not lossless.

    EscBuddy will convert this to a "safe" String literal you can use in your program, and the Escer Class can convert this to Unicode at runtime for your use:

    Code:
    strVar = Escer.UnEscape("\u0531\u0565\u0581\u0565\u0570\u056B \u056B\u0574 " _
                          & "\u056C\u0561\u057E ?\u0582\u0572\u056B\u0565 " _
                          & "\u056C\u0561\u057E\u0561\u0580\u0561\u0580")
    Note that I manually inserted the line breaks and concatenation above.

    You might also have multiline text with embedded Tabs and other control characters:

    Code:
    strVar = Escer.UnEscape("Line1\t<-tabbed to here\nLine2\nLine3\b\b\b<-3 backspaces")
    Or how about those pesky Shell() calls with quoted strings? For some reason a lot of people get frusted with VB6's native quote-escaping ("" = "):

    Code:
    "C:\Program Files\CommWiz\Send.exe" -p "D:\Plds\Dec Package.pkg"
    ... can be used as:

    Code:
    Shell Escer.UnEscape("\qC:\\Program Files\\CommWiz\\Send.exe\q -p \qD:\\Plds\\Dec Package.pkg\q")
    Escer and Hexer can also be useful for displaying Unicode or binary data to users in escaped form or in any of several hex formats.

    Feature List

    ESCER
    • Escape() method. Translate a plain text Unicode String to an escaped String.
    • UnEscape() method. Translate an escaped String to a plain text Unicode String.

    ESCER Escaping:

    Similar concept to that used in C-like languages, but a unique scheme tailored to VB6.
    • \xhh - 7 bit hex (00 to 7F)
    • \uhhhh - 16 bit hex ("Unicode")
    • \b - vbBack
    • \t - vbTab
    • \v - vbVerticalTab
    • \f - vbFormFeed
    • \r - vbCr
    • \l - vbLf
    • \n - vbNewLine/vbCrLf
    • \q - quote (")
    • \0 - vbNullChar
    • \\ - \

    Letters identifying escape sequences may be upper or lowercase.

    If an invalid escape sequence is found UnEscape() raises error 5 ("Invalid procedure call or argument").

    This is a "PredeclaredId" Class, so like a Form you get a "free" instance named the same as the Class for global use throughout your program.

    HEXER
    • HexFormat property. Set the translation format to any of four options.
    • BinaryToHex() method. Translate a Byte array to a hex String in the current format, optionally changing the format at the same time.
    • HexToBinary() method. Translate a hex String in the current format to a binary Byte array, optionally changing the format at the same time.

    HEXER Formats:
    • hfmtHex
    • hfmtHexAddr
    • hfmtHexAsciiAddr
    • hfmtHexRaw

    If the input does not match the current format HexToBinary() raises error &H80044100 ("CryptStringToBinary failed"). It is also possible for BinaryToHex() to raise error &H80044102 ("CryptBinaryToString failed").

    This is a "PredeclaredId" Class, so like a Form you get a "free" instance named the same as the Class for global use throughout your program.

    ESCBUDDY

    This program is meant as a developer tool and as a demonstration of the use of Escer and Hexer.

    It can be used to paste data in each of the available formats and see the results translated to the other formats. Then you can copy data in any of these formats back to the clipboard, e.g. to be pasted into the source code of a VB6 program.

    Author Name

    Bob Riemersma

    System Requirements

    ESCER:
    Should work in programs on any version of Windows from Windows 95 to current versions.
    HEXER, ESCBUDDY:
    Makes use of the CryptoAPI, so it may require Windows 2000 or later and might not work on Win9x.

    License Info

    Unencumbered freeware. No guarantee of support. Use at your own risk. This software is offered AS IS.

    Usage

    To use Escer and Hexer you can simply copy their .CLS files to your Project folder and use the IDE's Project|Add file... dialog to add them to your Project.

    To use EscBuddy compile the project provided and copy the EXE to whatever folder you want to keep it in. Create a Start Menu shortcut as desired.

    EscBuddy buttons all have Tooltip text that should be enough to explain their use. A separate "text" font and "hex" font (monospaced/fixed pitch) can be selected. Window position, fonts, etc. are persisted in the registry via the standard VB6 SaveSetting/GetSetting mechanism.

    Important Note:
    EscBuddy makes use of the Microsoft Forms 2.0 Object Library which is normally a poor choice for VB6 programs. However since this is meant as a developer tool this shouldn't be a problem.

    If you do not have the Forms 2.0 Library on your development system you will need to obtain and install it first. The only ways to get this library are to install a version of MS Office or MS Access - or locate, download, and install Microsoft's ActiveX Control Pad.

    The Forms 2.0 Library is not redistributable and is not intended for general use in VB6 programs. It is only used in EscBuddy as a convenient source of a Unicode-aware TextBox control, and it seems to work fine for my purpose here. Since you would never redistribute EscBuddy this should not be a problem.

    Comments

    The logic isn't highly optimized but in most cases it won't be used within tight loops anyway. You can always translate into a variable outside of your loops and used the cached result in your variable within your loops.

    There may be bugs as well, this hasn't been used exhaustively yet in its present form.

    See the source code, which contains comments elaborating on some of the features and limitations of the code.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Feb 9th, 2011 at 07:06 PM. Reason: serious bug fixed

Tags for this Thread

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