LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to limit the number of lines in a string?

hello all,

how is it possible to limit the number of lines in a string component?

I know a dirty way to limit the number of character but I want to limit the number of line (whatever is the number of character in a line providing that wrapping is enable).

The idea is to see the complete text in the string component without the possibility to add more text than displayed and or without using scrollbar.

Thanks in advance for your help.
0 Kudos
Message 1 of 7
(4,116 Views)
Hello Fabrice,
since the string control breaks the lines automatically, you cannot just determine how many linefeeds the string includes. But what about the "Get text rect.vi" from the pictures-palette? You could try word by word what width the string has, and if it exceeds the string-controls width, there would be a line break. Then try the next line...
But with a former project I found out, that this VI is not exact but maybe good enough for your needs.
Greets, Dave
Greets, Dave
0 Kudos
Message 2 of 7
(4,111 Views)
Hi Fabrice,

using 'Spreadsheet array to string' you can convert your string to an array. Now limit the number of array elements and convert back to simple string. Et voila!

When wiring the delimiter input of the 'spreadsheet to string' function you can adapt to different line delimiters!


Message Edited by GerdW on 02-02-2007 01:34 PM

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(4,105 Views)
thanks GerdW but this code can't work with the wrapping isn't it?

When I mean a line, it is not a string with an "return to line" character for delimiting but a line displayed in the string component.

The final application is to make sure that all the text that is typed in the string control is visible by the user. My idea was to limit the number of lines but could be an other solution.
0 Kudos
Message 4 of 7
(4,084 Views)
You don't say which version of LabVIEW you have, but this is a great candidate for an X-Control.
 
Create an xcontrol with a text control, then disallow key entried past a certain limit. Now the limits always work, even if the VI is in editing mode. 🙂
 
Another possibility is a filtering event on "key down?". Simply count the lines in the existing string (set to update while typing!) and discard (and e.g. beep!) if the limit is reached. The attached image shows a very quick draft. The lexical class check ensures that editing operations (backspace, etc.) still work after the limit is reached. Basically you only want to block readable characters. Most likely things need to be tweaked in a bit more detail.
 
(There are more efficient way of counting lines, using search&replaces is a quick hack ;))
 

Message Edited by altenbach on 02-02-2007 10:09 AM

0 Kudos
Message 5 of 7
(4,077 Views)
I made a VI, which counts the lines in a string control, considering the automatic wrapping.
Hope this helps,
Dave


Message Edited by daveTW on 02-02-2007 08:55 PM

Greets, Dave
Message 6 of 7
(4,066 Views)
Hi DaveTW,

it works quite fine but it does not worj correctly when there are empty lines (only with \n) inserted in the string.

How could we detected empty lines (inserted in the string and at the end of the string)?

Message Edité par Fabrice_M le 02-07-2007 11:33 AM

0 Kudos
Message 7 of 7
(4,040 Views)