LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change name of variable addressed programatically while looping

I've looked closely at your example and it still appears that you are just concatenating a string to make a new string and NOT using that new string as the NAME of the variable to use in the next loop.

If it can't be done, it can't be done.  

 

The example I provided is not limited to ASP.net - versions of C, Basic, Pascal (whether you put "visual" or "turbo" in front of the language name or not) etc. all have ways of using a variable as the name of a variable, expressly for looping situations.

 

 Because instrumentation so often involves multi-channel parallel program operations, I can only assume there is some way to do this with arrays that I am missing. 

0 Kudos
Message 21 of 29
(877 Views)

I've never seen what you are asking for in Basic or Visual Basic.  It has been a long time since I've used Pascal so I can't comment on that.  And I don't mess with C because I've never needed to do anything that Basic or LabVIEW couldn't do.

 

But why would you need this functionality?  If you have Variable1, Variable2, Variable3, you are trying to work with, why wouldn't you just make an array called Variable and work with indices.  So Variable(1), Variable(2), Variable(3) ...????

Message 22 of 29
(873 Views)

I would love to be able to make an array of these values.   I am reading item name values for four fields (one text, two numeric, one date) from 24 instances of a multi-column listbox, one for each of 24 channels..  These values are read from or written to control panel controls and may be read from or written to a file (as an array).  I use these values in several places as the sequence progresses.  To use an array, I would have to change all four values to one data type to upload to the array and reverse the process at every instance they are used.  The whole of idea of a local variable is to create it once and use it where needed.  The data is already the proper type for input and output.

 

I think you can see how be able to iterate the NAME of the variable would be helpful in this case. 

0 Kudos
Message 23 of 29
(868 Views)
My example did not upload using Chrome.  I try again with IE7
0 Kudos
Message 24 of 29
(865 Views)

As I said back in one of the messages, you can create an array of of references.

 

However, your data structure is a bit more complicated because you have essentially 5 references for different data types (2 strings, 2 numerics, 1 I32 list box) you want to group together, then make an array of that.  (See attachment) That is what a cluster is for.  Grouping dissimilar items.

 

You could also make separate arrays of references (one array for each datatype) and index out the appropriate reference for each item.

 

It may be a bit of work to generate all these references considering you are working with 5 types and 23 items of each type.  I believe there is a programmatic way to step through all the controls on a front panel, determine what they are by name, and build references out of that.  I'm sure there are some threads in the forum discussing how to discover controls by name.  I just haven't done that myself to be able to offer any advice.

 

You are working on a very ambitious project.  And getting the right data structure and architecture will make or break this project.  The wrong data structure such as just copying and pasting controls will kill you.  The right data structure might create a little bit of work up front, but make it easier to expand and work on in the long run.

 

You have a lot of local variables you are using that just don't look like you need them.  Also some repetitive Index Array functions where you are using 4 Index array to get elements 1, 2, 3, and 4.  If you use 1 Index Array, you can expand the bottom border downward.  Wire a 1 to the top index(nothing below that) and you will get items 1,2,3, and 4 all in one step.

 

I suggest you take a step back and rethink the whole architecture.  You already have a large VI, but it doesn't seem like it is really doing that much work yet.  I imagine there will be a lot more code to add for other functions and that will just exponentially grow your code.  Already, most of your code could be reduced by placing repetitive chunks in subVI's.  Start the project thinking about the architecture and only coding it for 2 or 3 of these items, always keeping in mind how you would add a 4th.  Once you do that, you'll easily be able to expand it to 23.

 

It looks like you are new to the forums, so I expect you don't have much LabVIEW experience yet.  Have you taken and LabVIEW courses such as Basics 1 and 2?  Or even Intermediate 1 and 2?  Intermediate is really geared towards thinking about expandable applications.

 

If not, have you looked at the online tutorials?  How to Learn LV

Message Edited by Ravens Fan on 03-18-2009 06:15 PM
Message 25 of 29
(860 Views)

Thanks for the tip on the Index Arrays, I should have thought of that one.   I have been doing engineering and programming in various languages since floppy disks were the size of mortarboard hats.  I did work halfway through "LabView for Everyone" before my bosses decided it was time to do something chargeable.  I have been testing two channel versions of this as it developed. Unfortunately, it is the "front end" for an existing, much larger vi that was 20 years in the making.  I will do some research on "array of references".  It does not seem to indexed in "Labview for Everyone" but I am sure there are examples on the Net.

 

Thanks for the assistance. 

0 Kudos
Message 26 of 29
(853 Views)

Hi Wild,

 

Ravens Fan gave you some good advise but I'll add waht I can to try and help.

 

FIrst I went for the curve ball. Sorry. In LabVIEW controls and indciators are just fancy "printf" statements not variables. Variables live inside wires or other structures so the examle I posted manipulated the variables inside wires.

 

Recreating my example should be possible going back to LV4 or ealier. It would be good for you to recreate that example and watch it execution highlighting mode (light bulb on while running) so you can see how looping structures work in LV.

 

I used looping structures like that along with the control references that Raven Fan mentioned in this Nugget on using Control Refs.

 

Please take a look at that nugget. Don't worry about understanding everything in that Nugget. It was written to address multiple levels. THe first part you may find most usefull.

 

So if you use the techniques in that Nugget and convert your GUI to be three tabs each containing a single cluster that in turn contains 16 cluster each of which has the values and parameters you are trying to initialize your first frame can be reduced to single sub-VI with a file spec and refences to you thre master clusters.

 

NI offers a 3-hour hands-on that they teach locally. That could give you a good start if you did not have time or money for Basics I & II.

 

Just rying to help (convert you),

 

Ben

 

Smiley Happy

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 27 of 29
(840 Views)

Another suggestion is to start working on your code and post it along with a description of what it does so far and what you want to accomplish.  We can make suggestions on how to achieve (or better achieve) what you are trying to implement.  I understand how difficult it is to convince managers that the investment on proper training is well worth its value.  The company would actually save money in the long run.   Until then, there's the forum 🙂

 

Follow Ben & Ravens Fan's advice. 


R

Message 28 of 29
(833 Views)

wildcatherder wrote:

Thanks for the tip on the Index Arrays, I should have thought of that one.   I have been doing engineering and programming in various languages since floppy disks were the size of mortarboard hats.  I did work halfway through "LabView for Everyone" before my bosses decided it was time to do something chargeable.  I have been testing two channel versions of this as it developed. Unfortunately, it is the "front end" for an existing, much larger vi that was 20 years in the making.  I will do some research on "array of references".  It does not seem to indexed in "Labview for Everyone" but I am sure there are examples on the Net.

 

Thanks for the assistance. 


You did not read far enough.

 

In the Third Edition, Chapter 15 talks about control references with topic on "Obtaining References to All Controls on a Front Panel" (page 763) and using arrays of refs (page 766).

 

Make SURE you read the section "The Value Property (is Evil) The Worst Kind of Global Variable"* that starts on page 773.

 

Ben

 

* Thank you Jim!

Message Edited by Ben on 03-19-2009 08:04 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 29 of 29
(825 Views)