Displaying A Varying Length List On Screen.


Recommended Posts

I am designing a test system that will test a pressure vessel.  It will control the pressure at various settings over time. There is a user input screen that allows the user to enter the number of steps for the test, the pressure jump per step, and the time between steps.

 

Ideally, I would like to present the user with text showing the sequence he has set.  E.g. the user sets a PSI step of 5 psi, the time for each step at 1 minute, and a total of 4 steps. Then the text box shows the following;

==========================

Step 1,  at 0 minutes 5 psi

Step 2, at 1 minutes 10 psi

Step 3,  at 2 minutes 15 psi

Step 4,  at 3 minutes 20 psi

Total Time for Test, 4 minutes.

==========================

 

The variable text display seems to only allow one line.  So, I can't just type a series of expression there.  But, the large expression window seems to hint that I can type a lot of stuff in there.

 

One possibility that I can think of is to write a separate script that concatenates a long string which gets set to a global variable.  The new lines might be created by embedding some carriage returns in the string. Then, the variable text display simply shows that single variable.  Is this a good approach?

 

 

Thank you for any advice,

-Joe

Link to comment
Share on other sites

Don't know how well a variable value display will do with multiple lines.

 

Ironically, I've found static text displays at times to a be more flexible way to display variable strings than a variable value display.  (You have to name the component, like MyTextDisplay, then write to it's value variable, Component.MyTextDisplay.strText, IIRC).  Static text displays will certainly do multiple lines, though when I've done that, I didn't really care where the line breaks were.  It was more of one single monolithic paragraph.  I'm pretty sure embedding line breaks will work, because you can enter multiple lines with breaks if you just type in static value to display.

 

You could also make multiple lines for Step 1, 2, etc. (either static text as described above or variable value display), and control the visibility of each with an expression like MaxStep > 1 for Step 2, MaxStep > 2 for Step 3, etc.

Link to comment
Share on other sites

  • 3 weeks later...

The best solution is to use the table component.  Maintain a string variable array for each column and populate that array and the table will update with its contents.

 

My data is currently in a 2-dimensional array. For discussion, lets say it has data like;

 

Row2;  A,B,C

Row1;  1,2,3

 

But, if I simply use the array name in the table, it displays

1

B

2

C

3

 

If I understand you correctly, I must first separate the rows into two separate arrays.  Would there happen to be a way to refer to each row as some sort of function?  I can't find one.  So, then I would have to create some for-next loops to create those separate arrays.  Correct?

 

-Joe

Link to comment
Share on other sites

Wrong dimension.  Each expression in the table component is a column, not a row.  So, if you have two variables:

 

global string x = {"A", "1"}

global string y = {"B", "2"}

global string z = {"C", "3"}

 

and you specify x, y and z as three columns in the table, you'd get what you want.  Note that the variables don't have to be strings, but you have A, B, C which are strings, so I made the entire column a string.

Link to comment
Share on other sites

I see that I was not clear in my question. My existing data in in a 2dimensional array. And I want it to be displayed, in essence, by rotating my example array by -90 degrees.  So, my resulting table needs to be displayed like this;

_________

| 1 | A |

| 2 | B |

| 3 | C |

 

I don't think your reply directly addressed my main issue.  However, I think your message does imply that I must use separate 1 Dimensional array for each column of the table.  Then, my task is to somehow parce out my 2D array.  Are there any array functions to help me do this?  Or do I need to create a for-next loop to read through the array and populate my 1D arrays that will be used on the columns?

 

-Joe

Link to comment
Share on other sites

So you want to go from an array with 3 columns and 2 rows, and have it display in 3 rows and two columns?  You can just use transpose to help you.  For the 1st column expression put: 

 

transpose(myarray[0], 0)

 

in the second do:

 

transpose(myarray[1], 0)

 

myarray[1] for example is an array with 3 columns and 1 row.  Doing transpose on it with ,0 means make it into 3 rows and one column.

Link to comment
Share on other sites

Again, I think I am not successfully communicating.  Transposing the table is not the issue.   My data is in a 2 dimensional array.  But, I can't simply put the name of the array as one of the columns, because then it lists both dimensions in the same column.  I need to somehow separate the rows and columns of data so they make sense to a human reader.

 

Perhaps there is a way to set a particular table column to show just one dimension of a 2D array?

 

Or alternatively, a way to set a 1D array equal to one of the dimensions in a 2D array?

 

In some previous messages, I proposed a for-next loop as a way to populate a pair of 1D arrays to use in the table display.  But, since you have not said "Yes, that that is the way to do it.", it suggests that there might be a better way that has not been mentioned or fully described yet... or I am somehow not recognizing it.

 

Can you tell me yes, or no, if the following is the best approach;

  1. Use a for-next loop to go through the 1st row of my 2D array.
  2. Append each value into a separate 1D array. [e.g. Row1Data]
  3. Use a for-next loop to go through the 2st row of my 2D array.
  4. Append each value into a separate 1D array. [e.g. Row2Data]
  5. In the table definition create two column displays.
  6. Set one of the 1D arrays [ Row1Data ] to one column,
  7. and the other 2D array [ Row2Data ]  to the other column.

 

-Joe

Link to comment
Share on other sites

Using loops to process arrays is really slow, especially when there is an alternative.  If you have an array, say, with 7 rows and 2 columns, and you just want the first row you'd do:

 

myArray[0]

 

if you just wanted the first column, you'd do:

 

myArray[][0]

 

That's how you slice arrays.  You could also do multiple columns, say you had 7 columns, and you just wanted the 2nd and 3rd:

 

myArray[][1,2]

 

same with rows:

 

myArray[1,2]

 

or, lets say you want the 2nd + 3rd rows, and 4th + 5th columns:

 

myArray[1,2][3,4]

 

Note of course that everything is 0 indexed, so 2nd = index 1.

Link to comment
Share on other sites

If I place a table on a page and size it large enough to hold 20 rows, have one or more columns with different background colors, and have 10 or fewer elements of data in the arrays populating the table, I get my 10 rows of data displayed as wanted but also get an undesirable bar of color extending below the table. It is filling with color to the full vertical size of the component even if there is not enough data to completely fill the component. It would be nice if the color stopped at the last row of actual data.

 

Is there a way to fix this? Maybe dynamically change the vertical size of the table based on the number of rows, but I don't know the size in pixels of each row.

Link to comment
Share on other sites

Dynamic table sizing is probably the best, or put a background color behind the table and resize that.  You should be able to figure out the pixel size of each row.  Remember, unless your mouse is over a graph, the status bar will show the pixel location of your mouse.  Use the OnPaint event of the table to change the component size based on the number of rows.  It'll be something like:

 

positionBottom = positionTop + 22 + iif(numRows(myChannel) < 10, numrows(myChannel) * 20, 200)

 

or:

 

positionBottom = positionTop + 22 + min(concat(numrows(myChannel) * 20, 200)))

 

where 22 is the number of pixels in the header, 20 is the number of pixels per row, 10 is the maximum # of rows before scroll, and 200 is 10 rows * 20 pixels per row.

 

I showed two ways just to demonstrate different ways of doing things with DAQFactory functions.  Note that min() takes an array only, thus the need for concat.  Its not like C where you do: min(x,y) and it returns the lesser of the two values.  Its just min(x) where x is an array and it returns the minimum value of that array.

 

Note also that OnPaint runs in the scope of the component.

Link to comment
Share on other sites

1) Putting a background color behind the table won't help. If you choose a background color for just one column but don't have enough rows of data to fill the table the background colored column shoots down the full height of the component. If the other table columns don't have a background color, you get this one column of color sticking out below your data. The table component is smart enough to figure out where to stop drawing the grid. It would be nice if also figured out how far to draw a column's background color.

 

2) I was experimenting with components on a page and my screen position stopped updating. I don't see why. Maybe you can tell me. I've attached a ctl file for you to try. Page 0 has components on it. When you select that page and move your mouse  there is no screen position update.

 

3) With a table you can get a scroll bar if there are more rows of data than will fit in the tables vertical size, and that's great for viewing the data on screen. But if you want to print a report including that data, you are only going to get a snap shoot of what's in the table on the printout. Is there an easy way to print the full table's worth of data on a report?

 

Thanks

Link to comment
Share on other sites

1) true.  You'd have to do all the background color items.

2) there wasn't an attachment

3) I usually create a separate page for printouts that is generally a duplicate of the display page, but with tweaks to allow it to print better.  For example, in your case, the other page would have the table component be much taller, probably completely off the bottom of your screen.  Even though its off the bottom of the screen, it will still print, at least with printPDF().  I don't use the built in printing often, since most customers prefer to save / email their reports, and DAQFactory printing directly can be flaky.

Link to comment
Share on other sites

I don't remember if it did this before or not, but  the cursor position does not update while resizing a component. It would be nice if it did. You know how big you want something to be but have to guess while resizing because the cursor position doesn't update.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.