PowerBASIC Peer Support Forums
 

Go Back   PowerBASIC Peer Support Forums > User to user Discussions > Source Code

Notices

Source Code PowerBASIC and related source code. Please do not post questions or discussions, just source code.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old Oct 10th, 2001, 08:57 PM
Borje Hagsten Borje Hagsten is offline
Member
 
Join Date: Jan 2000
Posts: 5,871
PB/DLL, Text to CHR$ converter..

Code:
' Simple text to CHR$ converter. Can be useful if we want to hide text strings
' in a program. Text like "Enter reg. code" is visible in compiled program code,
' but CHR$(69, 110, 116, 101, 114, 32, 114, 101, 103, 46, 32, 99, 111, 100, 101)
' is not and gives same output..  
'
' Can also be used to check ASC value(s) of any given character(s).
'
' Public Domain by Borje Hagsten, October 2001.
'------------------------------------------------------------------------------
#COMPILE EXE
#INCLUDE "WIN32API.INC"
 
%IDBTN_TXTCHR = 20
%IDBTN_CHRTXT = 21
%IDBTN_INFO   = 22
%ID_TEXT1     = 30
%ID_TEXT2     = 31
 
DECLARE CALLBACK FUNCTION DlgProc
 
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' MAIN ENTRANCE - create dialog and controls, etc
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
FUNCTION PBMAIN
  LOCAL hDlg AS LONG
 
  DIALOG NEW 0, "CHR$ converter", , , 255, 94, %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
 
  SetWindowPos hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE 'set dialog topmost
  DIALOG SHOW MODAL hDlg CALL DlgProc
 
END FUNCTION
 
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
' DIALOG MESSAGES
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
CALLBACK FUNCTION DlgProc
  SELECT CASE CBMSG
     CASE %WM_INITDIALOG
        LOCAL I AS LONG, txt AS STRING, txt2 AS STRING
        CONTROL SET FOCUS CBHNDL, %ID_TEXT1
 
     CASE %WM_DESTROY  'reset dialog topmost
        SetWindowPos CBHNDL, %HWND_NOTOPMOST, 0, 0, 0, 0, %SWP_NOMOVE OR %SWP_NOSIZE
 
     CASE %WM_COMMAND
        IF CBCTLMSG <> %BN_CLICKED THEN EXIT FUNCTION
        SELECT CASE CBCTL
           CASE %IDBTN_TXTCHR 'text to CHR$
              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 'CHR$ to text
              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)))))
                 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

------------------
__________________
PowerBASIC Staff
------------------
Private web-site: http://www.tolkenxp.com/pb
Free downloads: POFFS, incLean, PBcodec, custom controls and PB samples.
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:57 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright © 1999-2010 PowerBASIC, Inc. All Rights Reserved.
Error in my_thread_global_end(): 1 threads didn't exit