Lionheart008
30-06-2010, 17:48
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.
' 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
the example should works in both translation directions, try it :)
best regards, frank
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.
' 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
the example should works in both translation directions, try it :)
best regards, frank