Last Line and FormatTextAreaText
BlitzPlus Forums/BlitzPlus Programming/Last Line and FormatTextAreaText
| ||
I'm having trouble with FormatTextAreaText and the last line in a textarea. The last line in a textarea's does not include ASCII-13 (Return) and ASCII-10 (LineFeed). Each line other then the last will include these (hidden). For some reason this does not allow FormatTextAreaText to work properly. Any Idea's on how to get around this? L8r, |
| ||
Ok... To me this is looking very much like Bplus has a "BUG" with either passing a var. , or FormatTextAreaText has a problem accepting a var. for it's lentgh. When you run this code arrow up and insert a quote ("kkk"). You should see blue text from the open point of the quote to the end of the text. Now look at the status bar in the window. It shows the Quote starting charactor position as well as the length of the quote. They are right! When these vars are passed to FormatTextAreaText the starting charactor position gets through ok but not the length. If you were to replace the length var. in FormatTextAreaText with a litieral number it works. edit - See the Highlite function. Try it out for yourself. Let me know if this can be duplicated on other Windows systems other then Win98. Global Win1 Global TEXTAREA1 Global Tree1 Global Button1 CreateWin1() Global tcur ;load_command Global cmd_cnt Dim my_command_sort$(25,100) Dim my_command_index(25,1) Global s_command_flag Dim my_command$(1000) ;load_commands() Type element Field name$ Field row End Type Type token Field comment Field comment_pos Field o_quote Field o_quote_pos Field c_quote Field c_quote_pos Field quote End Type Type token_data Field token$ Field o_token_pos Field c_token_pos End Type Type token_quote Field o_quote_pos Field c_quote_pos End Type Global seperator$=";" AddTextAreaText textarea1,"kkkkkkkkkkkkkkkkkkk"+Chr$(10)+"kkkkkkkkkkkkkkkkkkk"+Chr$(10)+"kkkkkkkkkkkkkkkkkkk"+Chr$(10)+"kkkkkkkkkkkkkkkkkkk"+Chr$(10) HotKeyEvent 28,0,$103,28 ;retuen key Global root=TreeViewRoot( tree1 ) ActivateGadget textarea1 While WaitEvent()<>$803 id=EventID() If id=$401 ;gadget event event_gadget() EndIf If id=$103 ;on key event event_key() EndIf Wend Function event_key() es=EventData() Select es Case 28 End Select End Function Function event_gadget() Select EventSource() Case textarea1 row=TextAreaCursor( textarea1,2 ) syntax_highlite(row) End Select End Function Function syntax_highlite(row) total_rows=TextAreaLen( textarea1,2 ) tlength=TextAreaLineLen(textarea1,row);"Curnt Line Length (tlength):"+tlength charp=TextAreaChar( textarea1,row ) ;1st char Line (charp) ctext$=TextAreaText(textarea1,charp,tlength,1) ;line text get_token(ctext$) highlite(ctext$,charp,tlength) End Function Function get_token(ctext$) tpos=Len(ctext$) t.token=New token For i=1 To tpos ;Comment tk$=Mid$(ctext$,i,1) If tk$="'" And t\comment=0 t\comment=1 t\comment_pos=i EndIf ;Quote If tk$=Chr$(34)And t\comment=0 And q_flag_o=0 q_flag_o=1 tq.token_quote=New token_quote tq\o_quote_pos=i EndIf If q_flag_o=1 And tk$<>Chr$(34) q_flag=1 EndIf If tk$=Chr$(34)And t\comment=0 And q_flag=1 q_flag=0 tq\c_quote_pos=i t\quote=1 q_flag_o=0 EndIf Next End Function Function highlite(ctext$,charp,tlength) Local otmp ; Open position of quote Local ctmp ; Close Position of quote FormatTextAreaText (textarea1,0,0,0,1,(charp),(tlength),1) t.token=First token If t\comment=True FormatTextAreaText (textarea1,0,0,255,1,(charp+t\comment_pos)-1,((tlength)-t\comment_pos)+1,1) ;FormatTextAreaText (textarea1,0,0,255,1,(charp+t\comment_pos),((tlength)-t\comment_pos),1) EndIf If t\quote=True For tq.token_quote=Each token_quote ctmp=(tq\c_quote_pos - tq\o_quote_pos) otmp=(charp + tq\o_quote_pos) SetStatusText win1,"Open Quote Position:"+otmp+" Close Quote Length:"+ctmp FormatTextAreaText textarea1,0,0,255,1,otmp,ctmp,1 Delete tq Next EndIf Delete t ;FormatTextAreaText (textarea1,0,0,0,1,charp,tlength,1) End Function Function IsAlpha( i$ ) t=Asc(i$) If ( (t>=65 And t<=(65+26) ) Or (t>=97 And t<=97+26) ) Return True Else Return False EndIf End Function ; ----Function Begins---- Function CreateWin1() Win1 = CreateWindow("Window1",203,155,434,439,Desktop(),7+8) TEXTAREA1 = CreateTextArea(15,39,225,338,Win1,0) SetGadgetLayout TEXTAREA1,1,0,1,0 Tree1 = CreateTreeView(256,42,150,320,Win1,0) SetGadgetLayout Tree1,1,0,1,0 ;Button1 = CreateButton("Exit",273,323,118,44,Win1,0) ;SetGadgetLayout Button1,1,0,1,0 End Function Edit - I just edited this so I can copy it to BPlus bug reports.. This is some kind of BUG for sure. If I iterate a sequnce of numbers in a linear fasion into array then use the array to simulate a number it works. Adding this to the header of the code: Dim num(1001) For i=0 To 1000 num(i)=i Next Next to get FormatTextAreaText to work the length has to be done like this: FormatTextAreaText textarea1,0,0,255,1,pos,num(index),1 or to look at it from the highlite functions "point of view": Function highlite(ctext$,charp,tlength) Local otmp ; Open position of quote Local ctmp ; Close Position of quote FormatTextAreaText (textarea1,0,0,0,1,(charp),(tlength),1) t.token=First token If t\comment=True FormatTextAreaText (textarea1,0,0,255,1,(charp+t\comment_pos)-1,((tlength)-t\comment_pos)+1,1) ;FormatTextAreaText (textarea1,0,0,255,1,(charp+t\comment_pos),((tlength)-t\comment_pos),1) EndIf If t\quote=True For tq.token_quote=Each token_quote ctmp=tq\c_quote_pos-tq\o_quote_pos otmp=(charp + tq\o_quote_pos) SetStatusText win1,"Open Quote Position:"+otmp+" Close Quote Length:"+ctmp FormatTextAreaText textarea1,0,0,255,1,otmp-1,num(ctmp+1),1 Delete tq Next EndIf Delete t ;FormatTextAreaText (textarea1,0,0,0,1,charp,tlength,1) End Function This little fricken bug has haunted me for a month or more ... :( L8r, |