[VB6] Escer, Hexer Classes and EscBuddy Tool-VBForums
Results 1 to 8 of 8

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

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,626

    [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

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,626

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

    Before I forget, the real point of this was to make Escer.UnEscape() for use in your actual programs, as in:
    Code:
        txtUnescaped.Text = Escer.UnEscape(txtEscaped.Text)
    To do that you don't need all of Escer.cls, so you'd strip it down and make an EscerLite.cls with just the UnEscape() method in it.

    The same might be done with Hexer.cls of course, but again the point here was to simply make it easier to use more complex String literals in VB6 programs.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Feb 9th, 2011 at 08:27 AM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,626

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

    Ok, to begin with a serious bug was found and fixed in the version of Escer.cls that was posted as part of EscBuddy above. Fixed, and now reposted up there. The bug was not present in EscerLite, so no reposting for that above.


    After more use here and an old argument was thrashed out again another change was made. A biggy to us, but probably trivial from your viewpoint: We conclude that the choice of "\" as a string escape character in C is pointlessly painful for Windows development. There are just too many strings that must contain file paths, which use the "\" so often we find ourselves typing:

    c:\\abc\\defgh\\xyz.exe

    ... all the time. But we're talking VB here so we don't have to be encumbered by C and we've deviated far from C conventions already anyway.


    So we have a 2.0 edition of EscBuddy (and Escer.cls, and EscerLite.cls) that uses the "^" character as the escape character. You could use "`" or "~" or "|" or some other favorite little-used character, but we've decided we like "^" so here it is. You can always change it yourself to match your own preferences!


    So now:
    Code:
    "C:\Program Files\CommWiz\Send.exe" -p "D:\Plds\Dec Package.pkg"
    ... can more gracefully be encoded as:
    Code:
    Shell Escer.UnEscape("^qC:\Program Files\CommWiz\Send.exe^q -p ^qD:\Plds\Dec Package.pkg^q")
    ... and we avoid those ugly double-\ sequences we had in versions 1.x above.


    ESCER 2.0 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
    • ^^ - ^


    The attachment here has the bug fix made to 1.1, some UI changes, the switch from "\" to "^" and this archive has the updated EscerLite.cls and demo project in a subfolder too.
    Attached Files Attached Files
    Last edited by dilettante; Feb 9th, 2011 at 07:33 PM.

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

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

    I guess I'm going to be a pain in the beep, but...

    ^ character is troublesome, because if I type Shift + ^ key + u, I get &#251;.

    I have to type Shift + ^ key + space to get a ^ character and then press u to get ^u.

    For this reason I think it is a very poor choice.

    As a suggestion, do you see &#164; character being actually used anywhere? I've always wondered about that character because I never use it. Quite literally. And it is very rare for me to see it anywhere.

    Edit!
    But using &#164; character is not VB6 locale friendly... 164 is outside 32 – 127 range. Thus my suggestions probably go for # or _
    Last edited by Merri; Feb 10th, 2011 at 10:04 AM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,626

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

    The &#164; isn't available on my keyboard without doing Alt+0164 so that choice would be unsuitable here.

    Is there another choice that's usable? You could also just use any character you wanted but it would be nice to have something we all used if this kind of thing ever caught on. We liked the ^ because it makes a little more sense to us based on common use. For example in print control characters are often escaped as ^C for Ctrl-C, etc.

    But if there is another obvious choice (one guy here wanted "]" - bleh) I'm open to suggestions.

    The "\" was really getting to be a pain though, and we decided "/" was just as bad a choice because it gets used often for command line switches or division in a SQL statement... SQL being another reason to rule out "[" and "]" as choices.

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

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

    I edited my post just the same time with your newest post, but my current best shots are # or _. Nobody really uses neither of them in code a whole lot so it wouldn't be a major problem to use one of them. Also, more importantly, both of the characters are in the US-ASCII range and thus there will be no problems with VB6 IDEs that don't use Windows-1252 as their character set. And both of them are standalone characters, not linked to special keys that are used to write a wider range of characters.

    Edit!
    There is also the &#37; character which has a special meaning in url encoding.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,626

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

    The &#37; is used a lot in thinks like SQL LIKE patterns, so it finds itself in string literals quite a bit. Underscore gets used in a lot of things too like SQL table or field names and such.

    The # might be a good choice, and it stands out too. Sadly it gets used in HTML and XML entity encoding: &#x410; but most of us tend to have less of that anyway.

  8. #8
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    970

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

    i askd this already in the forums, but not getting any good respone. i am querying an sqlite database, searching for
    Code:
    ! @ # $ % ^ & * ( ) '
    that i saved ealier, but sqlite cant find it. the single quote ', accent ^, asteriks * etc all have meaning in sqlite database.
    i thought your program could help me convert and store these characters to comthing else, but its not helping.
    see what it converted the above characters to
    Code:
    /^n`^n|^n\^n#^n'^n[^n]^n@^n~^n(^n)^n>^n?^n:^n;^n$^n%^n^^^n&^n*^n!^n_^n-^n+^n=^n^u00AC^n^q
    the charcaters are still in the converted strings, any suggestions or help?
    Programming is all about good logic. Spend more time here


    (vHost for Apache) (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.