LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

change name of variable addressed programatically while looping

I might understand this one if I knew what SR was abbreviating.
0 Kudos
Message 11 of 29
(1,018 Views)

If you review my Nugget on Action Engines you will find that SR is an abreviation for Shift Register.

 

Ben

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

apparently I am trying to pass a variable by accessing its name but the name would change with each loop.

I can see people are trying to be helpful, I think it is just one of those things not possible in this programming language.  In other languages, one would concatenate the
"base name" with the loop integer and it would be recognized as the variable name, changing on each pass.

 

I would like to thanks those who tried to help and withdraw my question. 

0 Kudos
Message 13 of 29
(1,003 Views)

You can create an array of references then write to them by property node.  It's a little bit of work on the front end to create the references and build the array.  But once you have it, you have the array wire you can carry around.

 

 

 

In which other programming languages can you programmatically build a variable name?
Message Edited by Ravens Fan on 03-13-2009 05:40 PM
Message 14 of 29
(998 Views)

Example from ASP.NET

 

dim var1 
dim var2 
dim var3

for i = 1 to 7 
var3 = var2 & i 
process each time. 

loop 

 

 

Many other examples exist for other text-based programming languages. 

0 Kudos
Message 15 of 29
(986 Views)

I don't know if I'd consider ASP a real language.  I always thought it was some Microsoft web based hack.

 

Can it be done in VB or C++?

0 Kudos
Message 16 of 29
(972 Views)

HI Wild,

 

Thank you very much for the text based code.

 

I came from a texy text based background but never did ASP but I think I can guess at a transliteration* that may help but first notes.

 

1) LabVIEW handles all memory operation for us so we don't have to declare variable names. In LV we think wires instead of memory locations. Once you get used to that idea I hope that you will not miss having to declare variables.

 

2) SInce LV is graphical the structure differs from text. Instead code being structured from the top of that page to the bottom it is structured from the "root" (blank white space the diagram is built on) then into nested structure. ( The learning curve will be steeper if you come from a macro background where you have to turn your mental model inside out or upside down! Again, once you get used to it it makes it easier to apply to real world situations. It is like the difference between steering a boat with a rudder vs a steering wheel. You have to react differently to achieve the same result.)

 

Please code up this VI and watch it execute in Execution Highlighting mode (turn on the light bulb and watch it slow motion).

 

 

Note:

This code is a "verbose" version of the code I posted early in this thread. I re-wrote it so you could see each of the operations.

 

If you run into more Qs about coding in LV don't hesititate to post up.

 

Ben

 

* I use the term loosly.

Attached is LV 8.5
Message Edited by Ben on 03-14-2009 09:38 AM
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Download All
Message 17 of 29
(960 Views)

This looks more like what I had in mind.  I think I could suss it out if I had a LabView 8.0 - readable version of your example asp.vi   .  Is that possible? 

I knew I could concatenate strings but the trick is using that string to call the appropriate variable.

Thanks. 

0 Kudos
Message 18 of 29
(890 Views)

Code as much as you can then post your code when you get stuck.

 

Most of the cotributors to thsi forum will be albe to help with any trouble you may have duplicating that code.

 

Ben 

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

so it's not possible, I guess that is going to severly limit the usefulness of this forum to users of older versions.

 

0 Kudos
Message 20 of 29
(886 Views)