Jump to content

modify a variable name in a loop, how?


g_BonE
 Share

Recommended Posts

Guru's

once again i came across a little problem i cant solve myself. im trying to modify the name of a variable according to the return of a for-next-loop:

Dim $MyCount=4
Dim $ypos1=719

For $i=2 to $MyCount+2
  $ypos&$i=$ypos1+42
Next

...is this possible at all ?

Check out the Assign() function.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Guru's

once again i came across a little problem i cant solve myself. im trying to modify the name of a variable according to the return of a for-next-loop:

Dim $MyCount=4
Dim $ypos1=719

For $i=2 to $MyCount+2
  $ypos&$i=$ypos1+42
Next
oÝ÷ Ú+-+)¢Ë"nWµ©eþ«¨µæ(»kzØbH§À²È ©Ýö¥nëm«wöËÞ¯)®razè%˲¶(v«­¬°¢é]mé®r޶׫jëh×6Dim $MyCount=4
Dim $YPosArray[$MyCount + 3]
$YPosArray[0] = $MyCount + 2
$YPosArray[1] = 719

For $i=2 to $YPosArray[0]
     $YPosArray[$i] = $YPosArray[1]
Next

In the above example, the array is declared with seven elements [0 thru 6]. Element 0, accessed as $YPosArray[0], contains the number of other elements [6]. Your six variables are $YPosArray[1] thru $YPosArray[6]. Since you could change the number of elements by changing the variable $MyCount, you don't necesarily know the last element is [6]. But element [0] contains the number of the last element anyway, which is why the For/Next loop control looks the way it does, and will work no matter what you set $MyCount to.

No reason for array-a-phobia! :)

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

array-a-phobia!, thats the right word :). i couldnt think my head into doing what i wanted with an array tho it seems like a really nice way. i ended up using a if-then-else loop over the 8 possible enries similar to this:

if count >0 then
  ;only one entry
  $ypos1=$ypos1
endif
if count >1 then
  ;2 entries
  $ypos2=$ypos1+42
endif
if
  ;3 entries
  $ypos3=$ypos1+84
endif
;...and so on

thanks for the quick replies and helpful information. it's much appreciated !

Edited by g_BonE
...Fenster fährt mich Nüsse...
Link to comment
Share on other sites

array-a-phobia!, thats the right word :). i couldnt think my head into doing what i wanted with an array tho it seems like a really nice way. i ended up using a if-then-else loop over the 8 possible enries similar to this:

if count >0 then
  ;only one entry
  $ypos1=$ypos1
endif
if count >1 then
  ;2 entries
  $ypos2=$ypos1+42
endif
if
  ;3 entries
  $ypos3=$ypos1+84
endif
;...and so on

thanks for the quick replies and helpful information. it's much appreciated !

One day, Grasshopper, you will snatch this data from an array, then you will be ready... :P
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...