Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 3:42 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: a variable 'variable name' in script
PostPosted: May 6th, 2007, 9:20 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Just wondered if there is another way in scripting to create a variable name from passed parameters???
I use an array, which works fine, but is there another way?



function ReadCounter(Num)
{
ReadCount= new Array(2)
ReadCount[Num]=MyDLL.CallFn("ReadCounter","false","ulong","ulong",Num)
Debug.trace(ReadCount[Num]+"\n")
}

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 7th, 2007, 9:09 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Sorry sandyn slightly lost,

Might be coz, I don't have VI - yet, but the script would appear to read the result of the CallFn into the ReadCount array cell as specified by Num.

You question however, seems to be asking how to create a variable from the passed parameter IE I pass the string 'myVar' and then I use this to hold information

myVar = 'Information in here'


Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 7th, 2007, 2:12 pm 
Offline

Joined: January 19th, 2005, 5:15 pm
Posts: 83
Location: Netherlands
Hi Sandyn,


You could use eval for that. An example:

Code:

var counter = 10
for( i=0; i < 5 ; i++ ) {
    counter += 1
    eval(  'var_' + i + ' = counter' )
}


Top
 Profile  
 
 Post subject:
PostPosted: May 7th, 2007, 4:51 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
sorry....I didn't explained myself very well---basically, I was just trying to concatenate a string and a variable to create a new variable name...for example----value1, value2, value3 where the numerical part was from a loop count, so I'm trying to create ("value"+num)...where num is 1,2,3 from the loop count.
I just wondered if it can be done without using an array?

I'm not sure if the eval function would do that???

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 8th, 2007, 10:11 am 
Offline

Joined: January 19th, 2005, 5:15 pm
Posts: 83
Location: Netherlands
But do the string-values come from an array, or somewhere else?

Because eval can create new variables from a string and numbers:

Code:

var array = new Array('first', 'second', 'third', 'fourth')

for( i=0; i < array.length ; i++ )
{
    eval(  'var ' + array[i] + i + ' = \'value\' ' )
}




Top
 Profile  
 
 Post subject:
PostPosted: May 9th, 2007, 2:35 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Thanks Reemski. That does what I want!!

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 36 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group