Listbox display of entire 256 IBM DOS ASCII char set

Back in the DOS days, every ASCII character from 1 through 256 had a screen representation. Ten years ago I wrote a Hex File Dump and ASCII Edit utility that allowed the contents of  ANY file to be viewed and edited. Now I want to write something similar in VB5.

But ... I'm having problems displaying characters less than ASC(32) and greater then ASC(127).

What I'm looking for is a mix of (A) a multi-line textBox-like control and (B) a fixed TrueType font ... such that when combined allows display of the entire old IBM 256 ASCII character set. The solution must be 32 bit and I'm willing to purchase a special control and purchase a font if necessary.

Please do not attempt to answer this question unless you've actually TRIED the solution you propose. I've been programming for 25+ years and this problem does NOT have a simple solution. Everything I've tried "almost" works but have not yet found a way to display characters below 32 (especially characters like line feed, carriage return and tab).

I've made this question worth a lot of points because I want a real working solution, not someone's guess.

Thanks for your help

=================> Frederick Volking

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you've been programming for 25+ years, then you know you *can't* print characters below 32.  What you would need is code along the lines of:
If sChar = Chr$(10) Then
  Print "<LF>"
ElseIf sChar = Chr$(13) Then
  Print "<CR>"
and so on...(personally, I would use a Select/Case statement)

As far as a font that looks like the old MSDos characterset, try Terminal.  It's available on (almost) all Win95/NT machines and it is very similar.
To continue, there is an applet in Windows called Character Map which will display characters for any font you have installed.  Windows doesn't install the applet be default, so if you can't find the shortcut in Start/Programs/Accessories, you will have to add it with the Add/Remove Programs in Settings/Control Panel.
volkingAuthor Commented:
clifABB - You are wrong! Why did you Guess? I specifically asked for NO GUESSES!

It can be done. I know it can be done in DOS since I did it in two commercial product called DFD (Data File Doctor by Volking Software) and the second release called PDT (Programmers Data Tool by ProFormance Software). Of which I sold about $200,000 worth over 3 years.

I will emphasize ONE MORE TIME ... please DO NOT GUESS!

=================> Frederick
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

volking, why can't you continue to use a DOS box display?  You know that is also a generated system font, and it does represent all the characters, so why must it only be in a windows control display?  You can easily create a DOS task and wait for completion, and even position the window externally so that it looks like it is part of your windows app.

By the way there is a clue there.  It is done in a DOS box right now in Windows, so you know it can be done in Windows, since that also using a windows generated font.

Use the Terminal Font...  I did it using a listbox, and all chars print but 32, and that's a space so I guess it really did print.

Volking:  Your attitude definitely leaves a lot to be desired.
volkingAuthor Commented:
You propose an excellent idea however communication between the DOS window and VB5 is far beyond my knowledge level. The Hex Dump/ASCII Editor window is but a small portion of the overall functionality in the utility so I would need to setup intimate communication between the two. Simply stated, VB5 would need to print material to the DOS window and keystroke input from a cursor in the DOS window would need to be received by the VB5 application ... a tough scenario.

But thanks for your suggestion!

=============================> Frederick
I must deeply apologize.  I just wrote a scathing flame a mile high.  I had to delete it, though.  I just remembered the smiley face at chr$(1).

Unfortunately, you will not be able to find a font (true-type or other) which will dispaly any characters under 32.  This is a Windows thing.  Even if you tried to print a chr$(9), Windows will interpret it as it sees fit (as a tab).

To quote the VB Help file:
"Values 8, 9, 10, and 13 convert to backspace, tab, linefeed, and carriage return characters, respectively. They have no graphical representation but, depending on the application, can affect the visual display of text."
I will submit this as a comment, once you get this statement verified by other users and you accept that it can't be done, I hope you will give me the opportunity of submitting "It can't be done" as an answer.
volkingAuthor Commented:
AnthonyC - Thanks for your answer. At least you've tried your proposed solution. But what you suggest I've already tried and there's two problems. Here ... try this:

Text$ = String$(255, "X") + Chr$(13) + Chr$(10)
For C% = 1 To 255
Text$ = Text$ + Chr$(C%)
Text1.Text = Text$

The two lines are not identical lengths. Right? Because the tab (CHR$(9)) is translated & expanded. AND the two character pair  of (Chr$(13) + Chr$(10) is also translated into a line wrap otherwise the output would be one long line.

As I said, this is not an easy problem.

I apologize if my words to clifABB were abrupt. It was unintentional on my part. I was simply trying to be specific.

================================> Frederick

I stand corrected yet again (boy, I'm batting .000)

Terminal (which I suggested originally) does print a smiley face at chr$(1) as well as all the other DOS characters.
Volking, I have tried the code you suggested above in DOS and the chr$(9) is expanded there as well.  Also, the chr$(13) drops the printing down one line.
If you want a sample of using a DOS "console" there is a smple of doing just that in the VB owner's area on MSs VB site.  If you can't get there, e-mail and I'll post it.  Just thought it might be of help.
You may have to do a mask for the TAB key.. but not too much else (since the tab Key you describe is actually printing properly... it's representation is more than 1 space)
volkingAuthor Commented:
AnthonyC - That is exactly where I find myself right now. The only way I've found to make it work is to filter (a) all tab chars and (B) all CR+LF pairs. As a bad-case I could make it work. But I'd rather find a real solution ... thus this question.

I'll wait 24 hours then raise the points to 1,500 (which will wipe-out my account) but I really do want a clean solution.

Thanks for all your help.

=======================> Frederick
volkingAuthor Commented:
Changed my mind... why wait 24 hours ... if somone can solve this problem it's worth cleaning out my account. Heck, I'd even be willing to pay a few dollars, so email me direct if you're willing to work on this one.


====================> Frederick Volking
Check this out in the Microsoft Knowledge base.  

How to Print the ASCII Character Set in Visual Basic

Last reviewed: June 21, 1995
Article ID: Q75857
volkingAuthor Commented:
Cymbolic - This may be my answer!

I had to convert the API calls from VB3 to 32bit VB5 but the danged thing works! There's still a few problems like the text disappears when overlayed by another window and turning on the form's AutoRedraw makes the code stop working entirely ... but I might be able to make it work.

Please change your "Comment" posting to an "Answer" posting so we seal the question, then let me experiment for a day and verify that I can make it all work.

Many thanks!

I'll keep you posted.

=====================> Frederick
here is source that works:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Sub Command1_Click()
    Dim iSaved  As Integer
    Dim iHeight As Integer
    Dim lOEM    As Long
    Dim lObject As Long
    Dim iX      As Integer
    Dim iY      As Integer
    Dim szEdge  As String
    Dim szOut   As String
    Dim lRet    As Long
    Dim iCt     As Integer
    Dim iCt2    As Integer

      Dim hOEM As Integer   '*handle the OEM Font Object
      Dim y, H As Single

      '*save the scale mode so that you can reset later
      iSaved = Picture1.ScaleMode

      '*alter the current scale mode
      Picture1.ScaleMode = vbPixels

      '* get the character height and subtract the external leading
      iHeight = Picture1.TextHeight(Chr$(200)) - 1

      '* get the handle to the desired font
      lOEM = GetStockObject(OEM_FIXED_FONT)

      '* select the object relating to the font handle
      lObject = SelectObject&(Picture1.hdc, lOEM)

      '* if successful then print the desired characters.
      If lObject > 0 Then

         '* establish border
         szEdge = "0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 "

         '* initialize output location
         iX = 10
         iY = 10

         '* position cursor & print top border
         Picture1.CurrentX = iX
         Picture1.CurrentY = iY
         '* print top ruler edge
         szOut = "  " + szEdge + "  "
         lRet = TextOut(Picture1.hdc, iY, iX, szOut, Len(szOut))

         '* Cycle through 256 characters beginning at character 0
         For iCt = 0 To 15

            '* prep left border
            szOut = Mid$(szEdge, (iCt * 2) + 1, 2)

            '* assemble string of characters
            For iCt2 = 0 To 15
                szOut = szOut + Chr$((iCt * 16) + iCt2) + " "

            '* prep right border
            szOut = szOut + Mid$(szEdge, (iCt * 2) + 1, 2)

            '* prepare for display at next row
            iX = iX + iHeight

            '* print the assembled string of characters
            lRet = TextOut(Picture1.hdc, iY, iX, szOut, Len(szOut))


         '* prepare for display at next row
         iX = iX + iHeight

         '* print bottom border
         szEdge = "  " + szEdge + "  "
         lRet = TextOut(Picture1.hdc, iY, iX, szOut, Len(szOut))

         '* reinstate the previous font
         lOEM = SelectObject(Picture1.hdc, lObject)


         '* SelectObject was unsuccessful
         MsgBox "Couldn't Find OEM Fonts", 48

      End If

      '* reset the scale mode
      Picture1.ScaleMode = iSaved
   End Sub

Option Explicit

 ' Enter each Declare statement on one, single line.
Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long

Public Const OEM_FIXED_FONT As Long = 10

Cymbolic - I have to believe that AnthonyC was working on his "proof" when you posted your Q75857 resource. Since I originally made such a stink about wanting a solution that had been "tried", I think AnthonyC's answer best suited my request. By the way, AnthonyC's Proof works great!

Thanks AnthonyC! Thanks Cymbolic!

I sincerely appreciate BOTH your effort.

===========================> Frederick Volking
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.