Solved

Listbox display of entire 256 IBM DOS ASCII char set

Posted on 1998-05-22
21
644 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:volking
  • 6
  • 5
  • 5
  • +2
21 Comments
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
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.
0
 
LVL 5

Author Comment

by:volking
Comment Utility
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!

Thanks,
=================> Frederick
0
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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.

0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility
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.
0
 
LVL 5

Author Comment

by:volking
Comment Utility
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
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
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.
0
 
LVL 5

Author Comment

by:volking
Comment Utility
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%)
Next
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

0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:dochopper
Comment Utility
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.
0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility
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)
0
 
LVL 5

Author Comment

by:volking
Comment Utility
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
0
 
LVL 5

Author Comment

by:volking
Comment Utility
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.

FVOLKING@VISA.COM

====================> Frederick Volking
0
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
0
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
0
 
LVL 5

Author Comment

by:volking
Comment Utility
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
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 1490 total points
Comment Utility
here is source that works:


0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility

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) + " "
            Next

            '* 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))

         Next

         '* 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)

      Else

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

      End If

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



0
 
LVL 6

Expert Comment

by:anthonyc
Comment Utility
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



0
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now