Jump to content

Ascii Table + insert dialog


Mat
 Share

Recommended Posts

Here is the my latest addon for the program I'm writing. This one is an Ascii table that has the characters, decimal value, hex value and HTML codes (For some of them). The longest bit for me was compiling the html codes into a massive array, that took a while! its quite small, but does the job nicely.

There might be mistakes where values don't add up, probably with the html codes, so please tell me! I'm hoping this gets more replies than the last thing I posted here...

MDiesel

; #FUNCTION# ;================================================================
;
; Name...........: _InsertChar
; Description ...: Launches an ascii table that can be used to insert characters.
; Syntax.........: _InsertChar ($sTitle = "Ascii Table.", $nRetType = 0)
; Parameters ....: $sTitle - The title of the window.
;                  $nRetType - Specifies what should be returned. One of the following:
;                       0 - The character
;                       1 - the decimal code
;                       2 - the hex code
;                       3 - the HTML code
;                       4 - An array Of the previous 4
;                       -x - Where x is 0 to 4. Is the same as the previous 5 except the user cannot change the return value
;                            through the context menu. So the return will always be x.
; Return values .: Success - Returns as above (See $nRetType)
;                  Failure - Returns 0
; Author ........: MDiesel
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........; TBA
; #EXAMPLE# ;=====================================================================
#cs

$Ret = _InsertChar ("Title", -4) ; Must return array
If $Ret <> 0 Then MsgBox (0, "Result", "The Character is: " & $Ret[0] & @CRLF & "The decimal code is:" & $Ret[1] & @CRLF & _
    "The Hex Code is: " & $Ret[2])
#ce
;===============================================================================

Func _InsertChar ($sTitle = "Ascii Table.", $nRetType = 0)
   Local $hCharUI, $hList, $sCur = "", $hPrev, $hBtn, $hContext[6], $a, $Const = 0, $sOldSep = Opt ("GUIDataSeparatorChar"), _
      $sOldOnEvent = Opt ("GUIOnEventMode"), $hCancel, $sRet = 0
   Opt ("GUIDataSeparatorChar", "|")
   Opt ("GUIOnEventMode", 0)
   If $nRetType < 0 Then
      $Const = 1
      $nRetType *= -1
   EndIf
   If $nRetType > 4 Or $nRetType < 0 Then $nRetType = 0
   Local $aControlChars[32] = ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", _
      "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"]
   $hCharUI = GUICreate ($sTitle, 204, @DesktopHeight - 200, @DesktopWidth - 250, 0, -1, -1, 0)
      $hList = GUICtrlCreateListView ("Chr|Dec|Hex", 2, 2, 200, @DesktopHeight - 236, -1, -1)
         $hContext[0] = GUICtrlCreateContextMenu ($hList)
            $hContext[1] = GUICtrlCreateMenuItem ("Insert &Char", $hContext[0], 0)
            If $Const = 0 Then
               $hContext[2] = GUICtrlCreateMenuItem ("Insert &Dec", $hContext[0], 1)
               $hContext[3] = GUICtrlCreateMenuItem ("Insert &Hex", $hContext[0], 2)
            EndIf
            GUICtrlCreateMenuItem ("", $hContext[0], 4)
            $hContext[5] = GUICtrlCreateMenuItem ("C&ancel", $hContext[0], 5)
      $hPrev = GUICtrlCreateLabel ("", 5, @DesktopHeight - 232, 80, 40, -1, -1)
         GUICtrlSetFont (-1, 20, 1200, 0, "Courier New")
      $hBtn = GUICtrlCreateButton ("Insert", 80, @DesktopHeight - 232, 60, 30, -1, -1)
      $hCancel = GUICtrlCreateButton ("Cancel", 142, @DesktopHeight - 232, 60, 30, -1, -1)
      For $i = 1 To 31
         GUICtrlCreateListViewItem ($aControlChars[$i] & "|" & $i & "|" & StringRight (Hex ($i), 2), $hList)
      Next
      For $i = 32 to 123
         GUICtrlCreateListViewItem (Chr ($i) & "|" & $i & "|" & StringRight (Hex ($i), 2), $hList)
      Next
      Opt ("GUIDataSeparatorChar", "/")
      GUICtrlCreateListViewItem (Chr (124) & "/" & "124/" & StringRight (Hex (124), 2), $hList)
      Opt ("GUIDataSeparatorChar", "|")
      For $i = 125 to 255
         GUICtrlCreateListViewItem (Chr ($i) & "|" & $i & "|" & StringRight (Hex ($i), 2), $hList)
      Next
   GUISetState (@SW_SHOW, $hCharUI)
   While 1
   If StringInStr (GUICtrlRead (GUICtrlRead ($hList)), "124") Then
      If $sCur <> 124 Then
         $sCur = 124
         GUICtrlSetData ($hPrev, "|")
      EndIf
   Else
      If StringInStr (GUICtrlRead (GUICtrlRead ($hList)), "|") Then
         $a = StringSplit (GUICtrlRead (GUICtrlRead ($hList)), "|")
         If $a[2] <> $sCur Then
            $sCur = $a[2]
            GUICtrlSetData ($hPrev, $a[1])
         EndIf
      EndIf
   EndIf
   Switch GUIGetMsg ()
      Case -3
         $sRet = 0
         ExitLoop
      Case $hBtn
         $sRet = $sCur
         ExitLoop
      Case $hContext[1]
         $sRet = $sCur
         ExitLoop
      Case $hCancel
         $sRet = 0
         Exitloop
      Case $hContext[5]
         $sRet = 0
         Exitloop
   EndSwitch
   If $Const = 0 Then
      Switch GUIGetMsg ()
         Case $hContext[2]
            $nRetType = 1
            $sRet = $sCur
            ExitLoop
         Case $hContext[3]
            $nRetType = 2
            $sRet = $sCur
            Exitloop
      EndSwitch
   EndIf
   WEnd
   GUIDelete ($hCharUI)
   Opt ("GUIDataSeparatorChar", $sOldSep)
   Opt ("GUIOnEventMode", $sOldOnEvent)
   If $sRet <> 0 Then
      If $nRetType = 0 Then $sRet = Chr ($sRet)
      If $nRetType = 1 Then $sRet = $sRet
      If $nRetType = 2 Then $sRet = StringRight (Hex ($sRet), 2)
         Local $aRet[3] = [Chr ($sRet), $sRet, StringRight (Hex ($sRet), 2)]
         Return $aRet
      EndIf
   EndIf
   Return $sRet
EndFunc ; ==> _InsertChar

MDiesel

Edit: Undeclared Variables.

Edited by mdiesel
Link to comment
Share on other sites

Great Script, its one of those things that's good having laying around :)

[font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]
Link to comment
Share on other sites

yay!! a reply!!

Thanks cloafrysen, thats why I'm posting it.

I'm thinking of making a complete (ish) udf with lots of addons and dialogs such as these. I've written a fair few already - but when they get absolutely no replies it kinda makes me lose the will to live.

MDiesel

Link to comment
Share on other sites

Here is the my latest addon for the program I'm writing.

What are you writing??? :) It sounds very interesting...

I've only had time for a quick look and it looks good. :party:

Only problem is the bottom of the window is below the bottom of my screen.

Can I suggest a good "example" script would be one that calls your function then puts one of the 4 results (selected by button or list) on the clipboard. Maybe real useful. :-)

Well done

John Morrison

Edited by storme
Link to comment
Share on other sites

I'm writing another text editor (yes, this forum has plenty of those). But I've looked and none of them are any where near as full featured as the one I'm doing. Most are simple scripts with save and new functions. Mine has just passed 2000 lines, and does nothing. I am yet to build most of the functions too! Don't expect anything but addons for the next couple of months!

The problem with the window is easily solveable. And the first post has been updated to use macros. It now works on any screen with a height greater than 200pix. First post updated.

Thanks as always john

MDiesel

Link to comment
Share on other sites

Looks good but you don't really need all those html special codes.

example

&amp; can also be written as &

so all you really need is &# followed by the ascii decimal value and then the semi-colon.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

... great ... all that huge array for nothing!

The fact that my "reliable" source had stuff like #300 etc put me off I think...

Thanks geosoft, I'll edit that in a bit.

MDiesel

Edit:

Func _InsertChar ($sTitle = "Ascii Table.", $nRetType = 0)
   Local $hCharUI, $hList, $sCur = "", $hPrev, $hBtn, $hContext[6], $a, $Const = 0, $sOldSep = Opt ("GUIDataSeparatorChar"), _
      $sOldOnEvent = Opt ("GUIOnEventMode"), $hCancel, $sRet = 0
   Opt ("GUIDataSeparatorChar", "|")
   Opt ("GUIOnEventMode", 0)
   If $nRetType < 0 Then
      $Const = 1
      $nRetType *= -1
   EndIf
   If $nRetType > 4 Or $nRetType < 0 Then $nRetType = 0
   Local $aControlChars[32] = ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", _
      "SO", "SI", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"]
   $hCharUI = GUICreate ($sTitle, 204, @DesktopHeight - 200, @DesktopWidth - 250, 0, -1, -1, 0)
      $hList = GUICtrlCreateListView ("Chr|Dec|Hex", 2, 2, 200, @DesktopHeight - 236, -1, -1)
         $hContext[0] = GUICtrlCreateContextMenu ($hList)
            $hContext[1] = GUICtrlCreateMenuItem ("Insert &Char", $hContext[0], 0)
            If $Const = 0 Then
               $hContext[2] = GUICtrlCreateMenuItem ("Insert &Dec", $hContext[0], 1)
               $hContext[3] = GUICtrlCreateMenuItem ("Insert &Hex", $hContext[0], 2)
            EndIf
            GUICtrlCreateMenuItem ("", $hContext[0], 4)
            $hContext[5] = GUICtrlCreateMenuItem ("C&ancel", $hContext[0], 5)
      $hPrev = GUICtrlCreateLabel ("", 5, @DesktopHeight - 232, 80, 40, -1, -1)
         GUICtrlSetFont (-1, 20, 1200, 0, "Courier New")
      $hBtn = GUICtrlCreateButton ("Insert", 80, @DesktopHeight - 232, 60, 30, -1, -1)
      $hCancel = GUICtrlCreateButton ("Cancel", 142, @DesktopHeight - 232, 60, 30, -1, -1)
      For $i = 1 To 31
         GUICtrlCreateListViewItem ($aControlChars[$i] & "|" & $i & "|" & StringRight (Hex ($i), 2), $hList)
      Next
      For $i = 32 to 123
         GUICtrlCreateListViewItem (Chr ($i) & "|" & $i & "|" & StringRight (Hex ($i), 2), $hList)
      Next
      Opt ("GUIDataSeparatorChar", "/")
      GUICtrlCreateListViewItem (Chr (124) & "/" & "124/" & StringRight (Hex (124), 2), $hList)
      Opt ("GUIDataSeparatorChar", "|")
      For $i = 125 to 255
         GUICtrlCreateListViewItem (Chr ($i) & "|" & $i & "|" & StringRight (Hex ($i), 2), $hList)
      Next
   GUISetState (@SW_SHOW, $hCharUI)
   While 1
   If StringInStr (GUICtrlRead (GUICtrlRead ($hList)), "124") Then
      If $sCur <> 124 Then
         $sCur = 124
         GUICtrlSetData ($hPrev, "|")
      EndIf
   Else
      If StringInStr (GUICtrlRead (GUICtrlRead ($hList)), "|") Then
         $a = StringSplit (GUICtrlRead (GUICtrlRead ($hList)), "|")
         If $a[2] <> $sCur Then
            $sCur = $a[2]
            GUICtrlSetData ($hPrev, $a[1])
         EndIf
      EndIf
   EndIf
   Switch GUIGetMsg ()
      Case -3
         $sRet = 0
         ExitLoop
      Case $hBtn
         $sRet = $sCur
         ExitLoop
      Case $hContext[1]
         $sRet = $sCur
         ExitLoop
      Case $hCancel
         $sRet = 0
         Exitloop
      Case $hContext[5]
         $sRet = 0
         Exitloop
   EndSwitch
   If $Const = 0 Then
      Switch GUIGetMsg ()
         Case $hContext[2]
            $nRetType = 1
            $sRet = $sCur
            ExitLoop
         Case $hContext[3]
            $nRetType = 2
            $sRet = $sCur
            Exitloop
      EndSwitch
   EndIf
   WEnd
   GUIDelete ($hCharUI)
   Opt ("GUIDataSeparatorChar", $sOldSep)
   Opt ("GUIOnEventMode", $sOldOnEvent)
   If $sRet <> 0 Then
      If $nRetType = 0 Then $sRet = Chr ($sRet)
      If $nRetType = 1 Then $sRet = $sRet
      If $nRetType = 2 Then $sRet = StringRight (Hex ($sRet), 2)
         Local $aRet[3] = [Chr ($sRet), $sRet, StringRight (Hex ($sRet), 2)]
         Return $aRet
      EndIf
   EndIf
   Return $sRet
EndFunc ; ==> _InsertChar

Made a couple of other improvements too.

Edited by mdiesel
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...