Help understanding styleruns

I got this simplified code to work for reading the textArea, but is there a way I can read it directly from the listbox if it’s saved there using cellTag? I get a “this method or property does not exist” error if I try to say “st = listBox1.cell(0,0)”.

When user saves entry…

[code]dim st as StyledText
dim sr as StyleRun
dim i as integer

listBox1.addrow

listbox1.cellTag(0,0) = textArea1.text

st = textArea1.StyledText

for i= 0 to st.StyleRunCount - 1
sr = st.StyleRun(i)
if sr.Italic then
msgbox “” + sr.Text + “
end
next[/code]

AFAIK you cannot work in a styledText without the TextArea. When you do

 st = textArea1.StyledText

All you have is a pointer to the TextArea.StyledText. If you save it in your ListBox CellTag, all you save is a pointer.

Save StyledText.RTFData in the celltag, then when you need to detect styleruns, use an invisible TextArea to load back into it :

myInvisibleTextArea.StyledText.RTFData = listbox1.cellTag(0,0)

Afterward, you have again a styledText to work with.

ok that makes sense, but wouldn’t that take a heck of a long time if i have say 2000 entries to parse out?

Only a test can tell…

the other issue I suppose is allowing the user to set a portion of the text as italic. i understand how to assign a style to some text by using the selstart and sellength, but how would you determine what the selstart and sellength of selected text in the textarea? there does not seem to be any properties that determine whether or not some text is selected.

You don’t need to know that. Just loop through the styleruns and construct the output string based on the styles set and the text of each style run.

These are properties you can read. Once again, the LR is your friend : http://documentation.xojo.com/index.php/Textarea

i scoured the TextArea in LR but did not see how it could be done. Would it be TextEdit.CharPosAtXY? would need to figure out both the selstart and sellength which may not start at 0.

sorry for so many questions. i’m not a “real” programmer. my degree was in art. xojo has enabled me to do some pretty good stuff, though.

http://documentation.xojo.com/index.php/TextEdit.SelStart
http://documentation.xojo.com/index.php/TextArea.SelLength

As simple as reading properties …

well it’s pretty straightforward how you’d set the selstart and sellength programmatically, but what i was wondering is if a user highlights several words in the middle of the sentence and wants to hit the italic button i provide to change them to italic, how do I know which words they highlighted so i can set the selstart and sellength to set those words to italic in the textarea? i would obviously not know the integers before they decided which they wanted. it didn’t seem possible given those properties, which is why i raised the question.

At that point, the SelStart and SelLength are already set. Those properties serve to highlight text in the field, and are set automatically when the user highlights text. You just have to set SelItalic, etc., and the highlighted text will be affected.

I had hoped you understood from the clear description in the LR that Selstart and SelLength can be set, but can also be read. When the user clicks or double clicks the text, it changes these values. All you have to do is read them.

i’ve got it now. pardon my thickness. i do appreciate your mega-patience in helping a rank amateur like me. you guys are great!