Mark Yedinak Posted September 23, 2011 Report Share Posted September 23, 2011 I'm trying to create an intelligent string display that supports a scroll bar and auto scrolling. The auto scroll is easy. However, what I would like to be able to do is continue to auto scroll as long as the scroll bar is at the bottom. If the user moves the scroll position to something other than the bottom the automatic scrolling will be disabled. Again, this is easy to accomplish. The challenge though is to know when the user has position the scroll bar at the end again so auto scrolling can continue. My string indicator will allow for a fairly large string (10s of thousands of characters) and can contain binary data including the NULL character. The scroll position property is the line number that will appear in the top of the display. However, there doesn't seem to be any way of determining how many lines there are or how many lines the indicator thinks it has. It still has a concept of lines even if there are no actual carriage returns or line feeds in the data. Has anyone solved this issue? Does anyone have any ideas that may help. I have been struggling with a good way to determine when the user actually moves the scroll bar to the end position. And just to keep this challenging the indicator will be getting automatically updated with new data. I want to allow the user to move the scroll bar and not have the display jump to the bottom again as new data is added. I do however want them to be able to move the scroll bar to the bottom and effectively turn the auto scrolling on again. Quote Link to comment
Grampa_of_Oliva_n_Eden Posted September 23, 2011 Report Share Posted September 23, 2011 Without thinking to hard... Use a mouse up evnt to trigger checks of the scrol bar. Set the scroll position to infinity for auto-scroll. Ben Quote Link to comment
Ravi Beniwal Posted September 23, 2011 Report Share Posted September 23, 2011 Hi Mark, I created a VI that will count the number of lines in a string indicator. Number of Lines in String Indicator.vi The VI below will let you test it out. Currently, when you change the value of the string control, it recalculates the number of lines. String AutoScroll Main.vi I tried to test it while resizing the control with the pane, but I need to put some more work into it as it doesn't like the conditions changed on it while it is calculating. I'll add that and send you the VI again. As for the scroll bar, I'd suggest adding a separate scroll bar as it will give you more control over it and also you can catch the value change event for the scroll bar. Quote Link to comment
Saverio Posted September 23, 2011 Report Share Posted September 23, 2011 Ravi, FYI: your VI always returns a count that is one less than the actual number of lines. Quote Link to comment
Ravi Beniwal Posted September 23, 2011 Report Share Posted September 23, 2011 Good catch! I guess I just sent the line index out and not the number of lines. Quote Link to comment
PJM_labview Posted September 23, 2011 Report Share Posted September 23, 2011 Mark, Although I know that I have a utility that do exactly what you described I do not recall exactly how I did it. At lease now you know that it is possible. PJM Quote Link to comment
Ravi Beniwal Posted September 23, 2011 Report Share Posted September 23, 2011 OK, here are the updated VIs. Now "Number of Lines in String Indicator.vi" doesn't get if you resize the control or change its value, which could change the number of lines while it is calculating from the initial state. Number of Lines in String Indicator.vi String AutoScroll Main.vi Quote Link to comment
Mark Yedinak Posted September 23, 2011 Author Report Share Posted September 23, 2011 Thanks for the suggestions everyone. Unfortunately simply counting lines is not a solution that will work. In my case I have long strings with no new lines or carriages returns. In addition, if the text wraps in the string indicators what it considers to be the number of lines does not necessary reflect the true number of lines as determined by some end of line character. For example, this paragraph will only have a single end of line character yet within the string indicator it will be seen as multiple lines because of word wrap. If the size of the indicator changes the number of lines also changes. This is a very dynamic number (and somewhat random) in terms of the scroll position. Since I will be updating this display frequently I would like to avoid having to pass it through some line counter VI. I posted an idea in the LabVIEW Idea Exchange which asked for an auto scroll property built in for scrollable items. Hopefully this would include this functionality as well if they chose to implement it. If you have any other suggestions I am open to hearing them. Thanks. Quote Link to comment
Grampa_of_Oliva_n_Eden Posted September 23, 2011 Report Share Posted September 23, 2011 Did you try setting the scrool to plus infinity? Ben Quote Link to comment
Ravi Beniwal Posted September 23, 2011 Report Share Posted September 23, 2011 So Mark, how do you AutoScroll when the user moves the scroll bar to the end? If the scroll bar is controlling the scroll position, wouldn't the text automatically followed the scroll bar to the end while you were moving it there? I guess adding another button at the bottom of the scroll bar could be more intuitive. Here is what I have so far. Number of Lines in String Indicator.vi String AutoScroll Main.vi Can you send me some sample text that you are working with? Quote Link to comment
Darren Posted September 23, 2011 Report Share Posted September 23, 2011 Here's a weekly nugget where we described this very issue...I don't think there's a way to solve this without a "resume scrolling' button/action of some sort: Darren's Weekly Nugget 06/28/2010 Quote Link to comment
asbo Posted September 23, 2011 Report Share Posted September 23, 2011 I posted an idea in the LabVIEW Idea Exchange which asked for an auto scroll property built in for scrollable items. Hopefully this would include this functionality as well if they chose to implement it. Don't forget to whore it! Darren's Weekly Nugget 06/28/2010 This post made me realize you program without dots on wire junctions... you're crazy, man. Quote Link to comment
PJM_labview Posted September 23, 2011 Report Share Posted September 23, 2011 Mark, I dig up my code that do what you described. It is made of 2 VIs, one to do the string update + auto scroll and one that count the number of line. Since you seem to have a good handle on the auto scroll, here is the one that count the number of lines: Hope it help. PJM Quote Link to comment
Darren Posted September 23, 2011 Report Share Posted September 23, 2011 This post made me realize you program without dots wire junctions... you're crazy, man. Crazy like a fox! 2 Quote Link to comment
Mark Yedinak Posted September 26, 2011 Author Report Share Posted September 26, 2011 Thanks to all who responded. I found the solution in the thread Darrin posted above. I wish this functionality was built into LabVIEW but in the meantime I have a workable solution. Here is the test VI I was playing with to test it out. Auto Scrolling String Indicator.vi Quote Link to comment
Ravi Beniwal Posted September 26, 2011 Report Share Posted September 26, 2011 Hi Mark, Now I understand what you meant by moving the scroll bar to the end. I thought that this is a case like reading a large body of text and you wanted it to scroll as the user you read through it. I didn't realize it just had to keep the latest text visible, as it was added, if the scroll bar was moved to the bottom. Well, I guess now we have two solutions that could help at least two people Quote Link to comment
Jon Kokott Posted September 26, 2011 Report Share Posted September 26, 2011 I'll just throw this out there since I just did it and saw this post: I initialize a U32 Array (of size 1000) representing the string lengths of every line in the string indicator to length 1. I create a string of 1000 CR constants and store it in a DVR. Every time I concatenate to the log I get the length of the string I'm adding, build it to the length array, chop off the zeroth element of the array, and string subset based on that length. This approach will NOT limit the string length, but will limit the lines displayed. The scroll will simply stay at the position it was left at, so keep "scrolling." I add some functionality for stopping the "scrolling" by canceling the updates to the display during a mouse down, restarting during mouse up. The actual display updates were performed using a single element queue on a 100 ms timer (lossy enqueue) I've had success with what I consider a pretty unreasonably large string, I actually made the lines retained smaller because the scrollbar was so unmanageable when trying to go back. I should also note that this will only work if you know your log postings are one line and one line only. If you want to post a chapter book, best of luck with something else. Quote Link to comment
Ravi Beniwal Posted September 26, 2011 Report Share Posted September 26, 2011 Hi Mark, If keeping the scroll bar position at the bottom is all you need, you do not need to worry about the font or the indicator size. You just need to (try to) change the scroll position to a crazy large number. It will automatically take the largest value it can. Here's you VI, modified. Auto Scrolling String Indicator.vi Quote Link to comment
Mark Yedinak Posted September 26, 2011 Author Report Share Posted September 26, 2011 Thanks Ravi, but your simplified VI does not accomplish what I wanted. As I have stated I want the auto-scroll to keep the scroll bar position at the end of the display as new data comes in. HOWEVER, if the user moves the scroll position up I want to disable the auto scrolling until the user moves the scroll bar pointer back to the end position. And this has to work with data that does not have actual lines. The data my be what is effectively extremely long strings of arbitrary and possibly binary data with no carriage returns or line feeds. The solution I posted above mostly accomplishes this. In the actual application I will be using it I have found a case where I am unable to re-enable the auto-scrolling when I move the pointer back to the bottom. Quote Link to comment
Ravi Beniwal Posted September 26, 2011 Report Share Posted September 26, 2011 I guess while oversimplifying it, I totally missed that you were using the same crazy large number to scroll to the end. At least now, we didn't leave any aspect of scrolling string indicators, for others' sake! Quote Link to comment
Popular Post Aristos Queue Posted September 27, 2011 Popular Post Report Share Posted September 27, 2011 Early in this thread, someone posted some VIs for counting the number of lines in a VI. I'm not sure if you ended up using those, but there are some existing VIs that ship with LV that you might be interested in using. Since these VIs are not in the palettes, I recommend making a copy of them for your own code... Open up <labview>\vi.lib\utility\error.llb In there you'll find VIs for getting the longest line in pixels, the height of text given an amount of space (taking word wrapping into account), etc. These are used by the General Error Handler dialog. 4 Quote Link to comment
asbo Posted September 27, 2011 Report Share Posted September 27, 2011 I haven't looked at any VIs in this thread, but if you're not wiring an Inf+ constant for your "crazy large number", you should be. Quote Link to comment
MikaelH Posted September 27, 2011 Report Share Posted September 27, 2011 Don't forget that there is an invoke node to the String control that can "Get Nth Line". Quote Link to comment
Ravi Beniwal Posted September 27, 2011 Report Share Posted September 27, 2011 Don't forget that there is an invoke node to the String control that can "Get Nth Line". Hi MikaelH, we did use the "Get Nth Line" to count the number of lines, but that takes some iterations (and time) to come up with the number of lines and it didn't work for Mark. His solution works pretty well, where he is calculating number of lines from the font size. I haven't looked at any VIs in this thread, but if you're not wiring an Inf+ constant for your "crazy large number", you should be. The Text.ScrollPos property takes in a U32 number that can have a maximum value of xFFFFFFFF or d4294967295, which is the "crazy large number" that we were using. If you wire Inf+, wouldn't it be converted to the same U32 max of 4294967295? Quote Link to comment
asbo Posted September 27, 2011 Report Share Posted September 27, 2011 The Text.ScrollPos property takes in a U32 number that can have a maximum value of xFFFFFFFF or d4294967295, which is the "crazy large number" that we were using. If you wire Inf+, wouldn't it be converted to the same U32 max of 4294967295? I'm mostly poking fun The two are functionally equivalent, Inf+ is just pretty and more self-documenting, IMO. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.