Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 6:58 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: for loop question
PostPosted: April 11th, 2006, 2:24 pm 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
Hi,

I try to add some variables values with a for loop but don't know exactly how to do this.

I have 18 variables with names like "Question1", "Question2", "Question3" and so on. I would like to add the values of all 18 variables into the variable "Result".


I tried the following:

for (i = 1;18;++)
{Result = Result + (Question&i)
}

But this does not work.

Help is very appreciated.


T.

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


Top
 Profile Visit website  
 
 Post subject: Re: for loop question
PostPosted: April 11th, 2006, 2:53 pm 
Offline

Joined: November 3rd, 2004, 2:11 pm
Posts: 323
Try this:

for (i = 1;i<19;++)
{
Result = Result + eval('Question'+i)
}


Didn't test in Opus, but tested in JavaScript, so theoretically it should work.

_________________
Opus Pro XE 9.1 Win7 64-bit Core i3 8MB RAM


Top
 Profile Visit website  
 
 Post subject: Re: for loop question
PostPosted: April 11th, 2006, 3:10 pm 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
bwpatric wrote:
Try this:

for (i = 1;i<19;++)
{
Result = Result + eval('Question'+i)
}


Didn't test in Opus, but tested in JavaScript, so theoretically it should work.


... unfortunately not. It seems that the for loop is not executed a single time. I put a Debug.trace message into it which is not displayed when I start the loop by mouse click.

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 11th, 2006, 3:15 pm 
Offline

Joined: November 3rd, 2004, 2:11 pm
Posts: 323
Can you do it as a series of actions without scripting? I know it might seem like a lot of effort, but it might actually be easier when all is said and done.

_________________
Opus Pro XE 9.1 Win7 64-bit Core i3 8MB RAM


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 11th, 2006, 3:30 pm 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
bwpatric wrote:
Can you do it as a series of actions without scripting? I know it might seem like a lot of effort, but it might actually be easier when all is said and done.


I'm looking for a more elegant way because the number of questions changes often and I thought that this way is easier to work with.

Maybe someone else knows how to do it.


T.

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 11th, 2006, 3:44 pm 
Offline

Joined: November 28th, 2004, 6:05 am
Posts: 141
Location: USA
Hi T

I've run into this problem before when i is used previously in the script.
Try this

i=1
for(i=1;i<19;i++)
{
Result = Result+eval("Question"+i)
}

HTH
Chris

_________________
Opus Resources and Services


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 11th, 2006, 7:11 pm 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
... I don't know why but this does not work. I can use Result = Question1 + Question2 + Question3 ... instead. That works. Nevertheless it would be interesting to learn how to do this with a for loop.

Maybe someone of the DW team can help?


T.

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


Top
 Profile Visit website  
 
 Post subject:
PostPosted: April 11th, 2006, 9:40 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Chris has given you the correct answer -- you haven't
initialized the variables, so the loop won't fire.
Try this -- see attached pub.

cheers
Paul

// ########## Script ############

// initialise

var Result=0;

var Question1=10
var Question2=20
var Question3=30
var Question4=40
var Question5=50

for(i=1;i<6;i++)
{
Result = Result + eval("Question"+i)
Debug.trace("Accumulative Result "+i+" = "+Result + "\n"+"\n")
}

Debug.trace("Final Result = "+Result + "\n"+"\n")

// ########### end script ########


Top
 Profile  
 
 Post subject:
PostPosted: April 12th, 2006, 1:32 pm 
Offline

Joined: November 8th, 2004, 5:23 pm
Posts: 279
Opus: Opus Pro 9
OS: Win 10/64
Hi Paul,

thank you very much. This works.


T. :D

_________________
Opus Pro 9.75, Win 10/64, 8 GB RAM, Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 CPUs), ~3.4GHz, NVIDIA GeForce GTX 660 Ti, Roland OctaCapture


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 55 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