Page 1 of 1
Number of Lines
Posted: Thu Sep 30, 2010 8:29 pm
by tbohon
Is there a built-in way to retrieve the number of lines in a multiline stringgadget? I need to be able to pull the last line and then, later on, append a new line to the text.
Thanks in advance as always.
Tom
Re: Number of Lines
Posted: Thu Sep 30, 2010 8:42 pm
by Fluid Byte
Use the EditorGadget

Re: Number of Lines
Posted: Fri Oct 01, 2010 11:40 am
by #NULL
maybe a bit goofy, but why not like this
Code: Select all
CountString(GetGadgetText(0), #LF$) + 1
Re: Number of Lines
Posted: Fri Oct 01, 2010 2:15 pm
by Blood
#NULL wrote:maybe a bit goofy, but why not like this
Code: Select all
CountString(GetGadgetText(0), #LF$) + 1
Is this cross-platform?
Re: Number of Lines
Posted: Fri Oct 01, 2010 2:35 pm
by #NULL
it should work with windows (#CRLF) and linux (#LF). with some CompilerIfs it will work on mac os (#CR) too.
<edit>
tbohon wants to add a newline anyway, so in that case he will have to detect compiler_os to choose the appropiate newline character for all operations.
Re: Number of Lines
Posted: Fri Oct 01, 2010 3:02 pm
by RASHAD
@tbohon Hi
Take 'Fluid Byte' advice seriously
But if for some reasons you want to use StringGadget()
Next snippet For Windows
Compile it In Unicode mode
Code: Select all
Text$ = "Text in Multiline StringGadget with WordWrap and Line Number"
Linet$ = Space(#MAX_PATH)
OpenWindow(0,0,0,300,240,"String Gadget with WordWrap",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StringGadget(0,10,10,280,180,Text$,#ES_MULTILINE|#ESB_DISABLE_BOTH)
ButtonGadget(1,10,200,80,22,"Replace")
SetGadgetFont(0,LoadFont(0,"Arial",12))
NL = SendMessage_(GadgetID(0), #EM_GETLINECOUNT,0,0) ;Get No. of Lines
Debug NL
SendMessage_(GadgetID(0), #EM_GETLINE,Nl-1,@Linet$) ;Get the text in the last line
Debug Linet$
Repeat
EventID = WaitWindowEvent()
Select EventGadget()
Case 0
Case 1
If Run = 0
SetGadgetText(0,ReplaceString(GetGadgetText(0),RTrim(Linet$),"New String",1)) ;Replace Lastline Text with New
Run = Run +1
EndIf
EndSelect
Until EventID = #PB_Event_CloseWindow
Re: Number of Lines
Posted: Fri Oct 01, 2010 5:04 pm
by charvista
@RASHAD Hi
#EM_GETLINECOUNT works fine but #EM_GETLINE to get the last line does not work ?
Re: Number of Lines
Posted: Fri Oct 01, 2010 5:13 pm
by RASHAD
@charvista Hi
It is OK here PB 4.51 x86 Win 7 x64
What is your configurations?
And Remember to compile using Unicode
Re: Number of Lines
Posted: Fri Oct 01, 2010 6:06 pm
by charvista
@RASHAD Hi
Config: PB 4.50 x86 Vista x86
You are right. All my programs are compiled in Unicode, except when testing your code.
Compiled in Unicode gives correct results.
My fault, sorry.
Thanks Rashad
