Update Component Strcontents In A Loop ?


Recommended Posts

I have many edit box components from 0 to n. I name them box0 to boxn. 

I want to make those boxes showing the value of the variables assign to them when I update the variables. Is there a way to update the strcontents of those boxes using a foor loop?

For example (I tried the example below but won't work)

 

Private String BoxSeq

Global Variable

For (private i = 0, i < (n+1), i++)

    Variable = something_in_DoubleVal

    BoxSeq = "box" + DoubleToStr(i)

    Component.BoxSeq.Strcontents = Variable

Endfor

 

I have more than 100 boxes, instead of creating more than 100 lines of code such as below

Component.Box0.StrContents = DoubleToStr(Variable[0])

.

.

Component.Box100.StrContents = DoubleToStr(Variable[100])

Is there a way to update using a loop?

 

Link to comment
Share on other sites

Two ways:

 

1) following your logic of assigning the value to strcontents.  You are on the right track, but you need to use the execute() function, otherwise DAQFactory thinks you are trying to set a component called "boxseq", not one where the name is contained in a variable named boxseq.  What you want is:

 

execute("component." + boxseq + ".strContents = variable")

 

2) use page.updateEdits().  This single function will cause all the edit boxes to update with the current value of the Set To variable for that edit box.  This is actually most likely all you need unless you are trying to initialize the edit boxes with content that is different from what its set to variable is set to.

Link to comment
Share on other sites

Archived

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