Results 1 to 2 of 2

Thread: chr$ text converter (ui)

  1. #1
    Senior Member Lionheart008's Avatar
    Join Date
    Sep 2008
    Location
    Germany, Bad Sooden-Allendorf
    Age
    51
    Posts
    934
    Rep Power
    109

    chr$ text converter (ui)

    chr$: Convert one or more ASCII codes, ranges, and/or strings into a single string containing the corresponding ASCII character(s).
    this way I have build a little gadget for simple text to CHR$ converter. This can be useful if you want to hide text strings in a program.

    [code=thinbasic]' Empty GUI script created on 06-30-2010 17:19:08 by frank brübach (ThinAIR)

    Uses "ui"

    %IDBTN_TXTCHR = 20
    %IDBTN_CHRTXT = 21
    %IDBTN_INFO = 22
    %ID_TEXT1 = 30
    %ID_TEXT2 = 31

    Declare Function MessageBox Lib "USER32.DLL" Alias "MessageBoxA" (ByVal hWnd As DWord, lpText As Asciiz, lpCaption As Asciiz, ByVal dwType As DWord) As Long
    '------------------------------------------------------------------------------------------------------------------------------------------------------------

    Function TBMain() As Long
    Local hDlg As Long

    Dialog New 0, "Thinbasic CHR$ converter", -1, -1, 255, 110, %WS_CAPTION Or %WS_MINIMIZEBOX Or %WS_SYSMENU To hDlg

    Control Add Textbox, hDlg, %ID_TEXT1, "", 4, 4, 180, 40, %WS_CHILD Or %ES_MULTILINE Or _
    %WS_VSCROLL Or %ES_AUTOVSCROLL Or %ES_NOHIDESEL Or _
    %ES_WANTRETURN, %WS_EX_CLIENTEDGE
    Control Add Button, hDlg, %IDBTN_TXTCHR, "Text to CHR$", 190, 5, 60, 14
    Control Add Textbox, hDlg, %ID_TEXT2, "", 4, 50, 180, 40, %WS_CHILD Or %ES_MULTILINE Or _
    %WS_VSCROLL Or %ES_AUTOVSCROLL Or %ES_NOHIDESEL Or _
    %ES_WANTRETURN, %WS_EX_CLIENTEDGE
    Control Add Button, hDlg, %IDBTN_CHRTXT, "&CHR$ to Text", 190, 50, 60, 14
    Control Add Button, hDlg, %IDBTN_INFO, "&Info", 190, 76, 30, 14
    Control Add Button, hDlg, %IDCANCEL, "E&xit", 220, 76, 30, 14

    Dialog Show Modal hDlg Call DlgProc

    End Function

    '------------------------------------
    CallBack Function DlgProc() As Long
    '------------------------------------
    Local i As Long
    Local txt As String
    Local txt2 As String

    Select Case CBMSG
    Case %WM_INITDIALOG


    Control Set Focus CBHNDL, %ID_TEXT1

    Case %WM_DESTROY

    Case %WM_COMMAND
    If CBCTLMSG <> %BN_CLICKED Then Exit Function
    Select Case CBCTL
    Case %IDBTN_TXTCHR
    txt2 = ""
    Control Get Text CBHNDL, %ID_TEXT1 To txt
    If Len(txt) Then
    txt2 = "CHR$("
    For I = 1 To Len(txt)
    txt2 = txt2 & Format$(Asc(txt, I)) & ")"
    Next I
    txt2 = LEFT$(txt2, Len(txt2) - 2) & ""
    End If
    Control Set Text CBHNDL, %ID_TEXT2, txt2


    Case %IDBTN_CHRTXT
    txt2 = ""
    Control Get Text CBHNDL, %ID_TEXT2 To txt
    txt = Remove$(txt, Any "CHR$()")
    If Len(txt) Then
    For I = 1 To ParseCount(txt, ", ")
    txt2 = txt2 & Chr$(Max(9, Min(255, Val(Parse$(txt, ", ", I)))))
    's = Parse$(StringExpression, [Any] StringDelimiter, Index)
    Next I
    End If
    Control Set Text CBHNDL, %ID_TEXT1, txt2

    Case %IDBTN_INFO
    txt = "Text in upper textbox can be converted to CHR$(..) in lower," + $CRLF + _
    "ready for copying. Lower textbox can convert from CHR$(..)" + $CRLF + _
    "to text in upper. Use right-click menu in textboxes to copy, etc." + $CRLF + $CRLF + _
    "That's all, folks.. :-)"

    Call MessageBox(CBHNDL, ByVal StrPtr(txt), _
    "Information" + Chr$(0), %MB_OK Or %MB_ICONINFORMATION)

    Case %IDCANCEL : Dialog End CBHNDL
    End Select

    End Select
    End Function[/code]

    the example should works in both translation directions, try it

    best regards, frank
    Attached Images Attached Images
    Attached Files Attached Files
    you can't always get what you want, but if you try sometimes you might find, you get what you need

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: chr$ text converter (ui)

    Thanks Frank. Seeing any sort of conversion is magical. It brings out the wild imaginations of being an ancient commander devising a new way to send encrypted messages to others.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. TBGL OBJ to M15 converter [ UPDATED to v 1.5 ]
    By Petr Schreiber in forum TBGL Modelling, 3D, other SW integration
    Replies: 35
    Last Post: 18-08-2011, 16:37

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •