May 11, 2024, 12:17:02 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Detecting <cr>

Started by tbohon, April 03, 2007, 09:35:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tbohon

In a window with two controls - a richedit and a (smaller) edit control - I want to be able to detect a <cr> (x'0D) in the edit control, writing a message to the rich edit box.  I know how to do the writing - but I'm darned if I can figure out how to detect the <cr> in the edit control.  I know I'm going to be embarassed (again) when y'all show me how ... but I'm willing to risk the public humiliation since I've spent almost an hour 'playing' with a routine which doesn't work at all.

Tnx in advance as always.

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

GJ

April 04, 2007, 05:25:08 AM #1 Last Edit: April 04, 2007, 03:37:58 PM by GJ
Hi Tom,

I use the default button to detect if the enter was pressed, then display the text in the richedit control.
using the printm subroutine to do something with the text, like in the example bold and underline etc.

Good luck ,  ;)


Gertjan (GJ)



CONST EDIT_1 = 1
CONST RICHEDIT_2 = 2
CONST BUTTON_3 = 3
CONST STATIC_4 = 4
INT Infocus

DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Edit/Richedit",&d1_handler
CONTROL d1,@EDIT,"",                13,13,70,20,0x50800000,EDIT_1
CONTROL d1,@RICHEDIT,"",           141,15,70,60,0x50A00844,RICHEDIT_2
CONTROL d1,@BUTTON,"Button1",      230,28,70,20,0x40080001,BUTTON_3
CONTROL d1,@STATIC,"Type some text and press ENTER",13,37,77,44,0x50000101,STATIC_4
''CONTROL d1,@RICHEDIT,"",6,6,775,370,0x50B00844,RICHEDIT_2
DOMODAL d1

END


'--------------------------------------------------

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
       
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE EDIT_1
                 Infocus=1
/* respond to edit notifications here */
CASE RICHEDIT_2
                 Infocus=2
/* respond to control notifications here */
CASE BUTTON_3
                 IF GETKEYSTATE(13) <> 0 
                  SELECT infocus
                  CASE 1 
                  printm(d1,GETCONTROLTEXT(d1,1)) : 'print some text
                  SETCONTROLTEXT d1,EDIT_1,""     : 'clears the edit_1 control
                 CASE 2
                 SETFOCUS d1,EDIT_1 
                ENDSELECT 
              ENDIF 

ENDSELECT
ENDSELECT
RETURN
ENDSUB

'--------------------------------------------------

SUB printm(dialoog:dialog,text:string)
      'add some text on the next line to the richeditbox
      'place the cursor at the end of the textfile
      lengte = CONTROLCMD (dialoog, 2, @RTGETTEXTLENGTH)
''      CONTROLCMD dialoog , 2, @RTSETSELFONT,"Lucida Console",8,500,16  : 'lucida console gelijke chars
      controlcmd dialoog , 2, @RTSETSELECTION, lengte, lengte
      'add the text and a new line
      controlcmd dialoog, 2, @RTREPLACESEL, text + CHR$(13)+CHR$(10)
      CONTROLCMD dialoog, 2, @RTSCROLL, 0,1

RETURN
ENDSUB

'--------------------------------------------------

tbohon

Thanks, Gertjan ... I'll give this a shot.  Looking at your code I was close (as I suspected I probably was  ;D).  I think the problem is that I was trying to do this without having a button on the form/dialog ... which may not be possible.

Will play around a bit later today and see what happens.

Appreciate it!

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

Ionic Wind Support Team

In order to catch a CR in a multiline edit control you either need to use the notification code @ENCHANGE and check the text of the control for the CR, or subclass the edit control and catch the @IDCHAR message in the edit control handler.

Paul.
Ionic Wind Support Team

tbohon

Thanks, Paul.  Actually the input is done in the single line edit control and Gertjan's routine works just fine.

However, I'm a bit confused on the richedit control scrolling.  When I declare the richedit control thusly

CONTROL d1,@RICHEDIT,"",6,6,775,370,0x50B00844,RICHEDIT_2


and start entering lines in the single line edit control (EDIT_1), everything is fine until I reach the bottom of the visible screen.  At that point it doesn't automatically scroll down so that the last line entered is visible - at least until I manually move the vertical scrollbar down, after which it 'behaves' itself.

Is there something else I need to do to have the last line entered in the (readonly) richedit control above always visible, i.e., to force the vertical scroll down?

Tnx in advance.  Appreciate the assist.

Tom
"If you lead your life the right way, the karma will take care of itself ... the dreams will come to you."  -- Randy Pausch, PhD (1961-2008)

GJ

Hi Tom,

Modified the code a bit, still i am a beginner with Ebasic, but i like it a lot !
Maybe i need a simple subclass demo for my programs to understand how that works. Till now i'm happy with it how it is, still a lot
learning for me  ;D



Gertjan