LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

text box line grows in length when I replace last line

Hi,
I have a text box, which I am using as a terminal. Therefore, it is set as an indicator only and I send what is typed into it over the serial port and then add the responce to the box myself using SetCtrlVal.
The problem that I am having is that when I recieve a backspace I would like to remove one charactor out of the box. I do this by reading the last line, deleting the last character out of it and then replacing that line with the modified one. I also move the cursor back one space as well:
GetNumTextBoxLines (thru_panel, COM_THRU_TEXT, &line);
GetCtrlAttribute (thru_panel, COM_THRU_TEXT, ATTR_TEXT_SELECTION_START, &cursor);
GetTextBoxLine (thru_panel, COM_THRU_TEXT, line-1, lbuf);

lbuf[strlen(lbuf)-1] = '\0';
ReplaceTextBoxLine (thru_panel, COM_THRU_TEXT, line-1, lbuf);
SetCtrlAttribute (thru_panel, COM_THRU_TEXT, ATTR_TEXT_SELECTION_START, cursor-1);
However, when I do a replace It adds a new line at the end of the of the text buffer, and any new text that I append goes on this new blank line rather than at the end of the previous line where the cursor is. I try to delete this line, but it will not delete. Any ideas?
thanks
jackson
0 Kudos
Message 1 of 4
(3,083 Views)
Hi Jackson,
I was able to replicate this problem and figure out what seems to be going wrong. Originally I was seeing the same thing happen, but after investigating further I found that the GetNumTextBoxLines seems to give back one more than the number of lines shown. I had four InsertTextBoxLines in a row and the function returned the number five. The text box must create an extra line for the next line of text it will be given. Given the fact that the function returns one more than what the users see and the fact that the ReplaceTextBoxLine function takes a zero indexed value, you should subtract two from your line variable instead of one.

I hope this helps you out!

Best Regards,
Aaron Kobayashi,
Application Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,083 Views)
I looked at this and it is partially correct. If all I have done is insert text using SetCtrlVal, then GetNumTextBoxLines does return the correct number of lines. However, once I edit the box using the line based commands (Insert/Replace/Delete)TextBoxLine, it is then that GetNumTextBoxLines returns one more line than is used. Furthermore, subsequent calls to SetCtrlVal place text on this new line, rather than appended to the end of the previous line. There seems to be a conflict between how SetCtrlVal edits the text and how the line based commands edit the text. I will try to replace SetCtrlVal calls with equivilant line based commands, so that everything I do is consistant. I will let you know if this leads to a solution.
0 Kudos
Message 3 of 4
(3,083 Views)
Okay,
I got it to work by only using the line based commands and not SetCtrlVal. I can throw together a small test program if you'd like. I have one more question though, first. Why does the text box only have the ATTR_HSCROLL_OFFSET attribute, and not ATTR_VSCROLL_OFFSET?
jackson
0 Kudos
Message 4 of 4
(3,083 Views)