Display ASCII Table

Category: Apps/Dialogs

Date: 07-23-2010

Return to Index


 
'For all the times you just wanted to remember the ASCII code
'here's a Sub that will simply pop up a msgbox with the printable
'characters of the ASCII code tab
 
'Use a button to call it up, but a menu with an accelerator would
'be best to put it at your fingertips.  The compilable example below
'shows how to add accelerator keys to your app.
 
'In Brief:   A-Z    65-97
'            a-z    97-122
'            0-9    48-57
 
'Primary Code
Sub ShowASCIITable
   Local temp() As String, i As Long, all$
   Dim temp(32)
   For i = 0 To 31
      temp(i) = Chr$(i+33) + Chr$(9) + Str$(i+33)
   Next i
   For i = 0 To 31
      temp(i) = temp(i) + Chr$(9) + Chr$(9) + Chr$(i+65) + Chr$(9) + Str$(i+65)
   Next i
   For i = 0 To 31
      temp(i) = temp(i) + Chr$(9) + Chr$(9) + Chr$(i+97) + Chr$(9) + Str$(i+97) + Chr$(9)
   Next i
   all$ = Join$(temp(), $CrLf)
   all$ = all$ + $CrLf + $CrLf + " 0  null" + $Tab + $Tab + "12  formfeed (FF)"
   all$ = all$ + $CrLf + " 8  backspace" + $Tab + "13  carriage return (CR)"
   all$ = all$ + $CrLf + " 9  tab" + $Tab + $Tab + "27  escape (ESC)"
   all$ = all$ + $CrLf + "10  linefeed (LF)" + $Tab + "32  space"
   MsgBox all$, %MB_Ok+%MB_IconInformation, "ASCII Table"
End Sub
 
 
'Compilable Example:
'This allow 3 ways to call the table: button, menu, accelerator key
#Compile Exe
#Dim All
#Include "Win32API.inc"
#Include "CommCtrl.inc"
%ID_ASCIITable = 100 : %IDC_Button = 200
Global hDlg As DWord, hMenu As DWord, hMenuOptions As DWord
 
Function PBMain() As Long
   Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
   Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20
   AddMenu
   BuildAcceleratorTable
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   If CB.Msg = %WM_Command AND CB.Ctl = %IDC_Button Then ShowASCIITable
   If CB.Msg = %WM_Command AND CB.Ctl = %ID_AsciiTable Then ShowASCIITable
End Function
 
Sub BuildAcceleratorTable
   Local c As Long, ac() As ACCELAPI, hAccelerator As DWord  ' for keyboard accelerator table values
   Dim ac(0)
   ac(0).fvirt = %FVIRTKEY Or %FCONTROL
   ac(0).key   = %VK_T
   ac(0).cmd   = %ID_AsciiTable
   Accel Attach hDlg, AC() To hAccelerator
End Sub
 
Sub AddMenu()
   Menu New Bar To hMenu
   Menu New Popup To hMenuOptions
   Menu Add Popup, hMenu, "&Option", hMenuOptions, %MF_Enabled
   Menu Add String, hMenuOptions, "&Option ASCII Table" + $Tab + "Ctrl-T", %ID_AsciiTable, %MF_Enabled
   Menu Attach hMenu, hDlg
End Sub
 
Sub ShowASCIITable
   Local temp() As String, i As Long, all$
   Dim temp(32)
   For i = 0 To 31
      temp(i) = Chr$(i+33) + Chr$(9) + Str$(i+33)
   Next i
   For i = 0 To 31
      temp(i) = temp(i) + Chr$(9) + Chr$(9) + Chr$(i+65) + Chr$(9) + Str$(i+65)
   Next i
   For i = 0 To 31
      temp(i) = temp(i) + Chr$(9) + Chr$(9) + Chr$(i+97) + Chr$(9) + Str$(i+97) + Chr$(9)
   Next i
   all$ = Join$(temp(), $CrLf)
   all$ = all$ + $CrLf + $CrLf + " 0  null" + $Tab + $Tab + "12  formfeed (FF)"
   all$ = all$ + $CrLf + " 8  backspace" + $Tab + "13  carriage return (CR)"
   all$ = all$ + $CrLf + " 9  tab" + $Tab + $Tab + "27  escape (ESC)"
   all$ = all$ + $CrLf + "10  linefeed (LF)" + $Tab + "32  space"
   MsgBox all$, %MB_Ok+%MB_IconInformation, "ASCII Table"
End Sub
 
'gbs_00009
 


created by gbSnippets: http://www.garybeene.com