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
Number of Lines
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Number of Lines
maybe a bit goofy, but why not like this
Code: Select all
CountString(GetGadgetText(0), #LF$) + 1
Re: Number of Lines
Is this cross-platform?#NULL wrote:maybe a bit goofy, but why not like thisCode: Select all
CountString(GetGadgetText(0), #LF$) + 1
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
Re: Number of Lines
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.
<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
@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
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
Egypt my love
Re: Number of Lines
@RASHAD Hi
#EM_GETLINECOUNT works fine but #EM_GETLINE to get the last line does not work ?
#EM_GETLINECOUNT works fine but #EM_GETLINE to get the last line does not work ?
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: Number of Lines
@charvista Hi
It is OK here PB 4.51 x86 Win 7 x64
What is your configurations?
And Remember to compile using Unicode
It is OK here PB 4.51 x86 Win 7 x64
What is your configurations?
And Remember to compile using Unicode
Egypt my love
Re: Number of Lines
@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
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

- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%