SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-21-2009, 01:50 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Way to change variable in a loop

Is there a way to loop and change the variable everytime if the variable only changes by a number for example

i = increasing increment
variablename = Title + increament

If I try Title+1 = value of course that doesn't work but is there a way?
Reply With Quote
  #2  
Old 08-21-2009, 03:17 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
I'm not entirely sure I understand the question, but it sounds like you're trying to assign to a different variable name each time through the loop. If that's correct, don't use separate variables; use an array that you can index using SetElement.

You can also use a case statement to do the assignment:

Code:
If i
  > 1
    var1 = value
  > 2
    var2 = value
  ...
but that's bulky and less efficient because it has to test each case every time through the loop.

A third option, which I hesitate to even mention for fear of abuse, is to assemble a statement in string form (e.g. "var" + i + " = value") and use EvaluateExpression to execute it. This may seem like a clever trick, but really it should be your very last resort in truly exceptional circumstances where there's just no other good way to accomplish what you want. You should resist the temptation to use it widely because it's an extremely inefficient way to execute code and also tends to obscure the meaning of your code.

If what you want is a collection of related variables indexed by number, use an array. That's what they were invented for.
__________________
-- Greg
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
delay_to_wait_after_tuning variable fract4l SageTV Linux 1 02-08-2009 01:51 PM
Table with variable size cells bialio SageTV Studio 13 01-21-2008 03:05 PM
DisplayIndex as a global variable? Crashless SageTV Studio 2 12-30-2007 11:01 AM
Must be doing something stupid, can't pass a variable to a new menu. stanger89 SageTV Studio 14 02-23-2007 05:24 PM
Variable playback speeds... grooves12 SageTV Customizations 0 03-04-2006 04:46 AM


All times are GMT -6. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.