May 06, 2024, 01:17:41 AM

News:

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


RICHEDIT Question

Started by mrainey, March 13, 2008, 08:38:10 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mrainey

I'm struggling a little with the @RTGETLINELENGTH function and seeing something I wanted to ask about.  In the following code, I'm having to add the number of characters in a line, plus two, to index to the next line.  Are the two extra for CR/LF?  Is there a way to just specify the line number instead of the character index?



AutoDefine "Off"

Def EditWin:Window
Def a:Int
Def Run:Int
Def TestString:String

Const EditColor = 0xafe1e1
Const Cameo = 0xe6fafa
Const Black = 0x000000
Const redTest = 1


OpenWindow EditWin,-1000,-1000,240,240,@MinBox|@NoAutoDraw,0,"",&HandlerEdit
SetWindowColor EditWin,EditColor
SetCaption EditWin,"richedit test"


Control EditWin,@RichEdit,"",20,20,200,180,@CTEditLeft|@CTEditMulti,redTest
SetControlColor EditWin,redTest,Black,Cameo

a = ControlCmd (EditWin,redTest,@RTSetDefaultFont,"Tahoma",8,1,0)
a = ControlCmd (EditWin,redTest,@RTSetMargins,20,10)

TestString = Append$("Hello","\n","Goodbye","\n","Huh?")
a = ControlCmd (EditWin,redTest,@RTLoad,TestString,0)

a = ControlCmd (EditWin,redTest,@RTGetLineLength,0)  : 'a = 5  Hello
'a = ControlCmd (EditWin,redTest,@RTGetLineLength,7)   : 'a  = 7 Goodbye
'a = ControlCmd (EditWin,redTest,@RTGetLineLength,16)   : 'a = 4  Huh?


CenterWindow EditWin

messagebox EditWin,"line length = " + Str$(a),"Info"


Run = 1
WaitUntil Run = 0
End


Sub HandlerEdit
    Select @Message
        Case @IDCloseWindow
            CloseWindow EditWin
            Run = 0
    EndSelect
Return
EndSub

Software For Metalworking
http://closetolerancesoftware.com

LarryMc

Maybe I don't understand your question (or am missing something) but doesn't this do it?

QuoteCONTROLCMD ( window | dialog, ID, @RTGETLINE, linenum, line$ {,cchLine})
Use this function to retrieve a line of text from the rich edit control.
Linenum is the 0 based index of the line to retrieve, cchLine is the size of the line$ STRING variable, defaults at 255.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

mrainey

Thanks Larry,

I'm working on a program to parse text files (CNC programs, actually) and make a ton of calculations based on the contents.  File length could be anything from a few lines to a few thousand, all text, and with a good bit of room for format variability.  A predictable format makes it much easier to parse the individual elements, and I've gotten real good at reformatting stuff like this in UltraEdit, using macros and regular expressions.  Obviously, doing it inside of Emergence presents different challenges.

After reading a tip from TronDoc (RIP) in the old Pyxia forum content, I decided to load a sample file into a rich edit control and try to do some reformatting there.  So far it's not bad (no global replace or regex), but I've gotten it to give me what I want.  Like everything else in programming, you just have to figure out what the darn thing is looking for (in a hundred tries or less  :D ).
Software For Metalworking
http://closetolerancesoftware.com