Jump to content

Creating variables in a For function


Go to solution Solved by mpower,

Recommended Posts

Posted
Hey guys, i'm trying to creating 7 variables in a "For" function, to not declare one by one.
But i get errors, here is the code:
Local $i = 0
Local $bday = _DateAdd("D", -$i, _NowCalcDate())
;

For $i = 0 To 6
    Local $bNewDate[$i] = 0
Next

;Options
Local $aArray[7] = [$bNewDate[6], $bNewDate[5], $bNewDate[4], $bNewDate[3], $bNewDate[2], $bNewDate[1], $bNewDate[0]]

Are this code stupid or am i stupid for don't see the error hahaha

Sorry i'm noob as a Autoit programmer  >_<

  • Solution
Posted

Here is an example:

#include <Date.au3>
#include <Array.au3>

Dim $variables[7]

For $i = 0 To Ubound($variables) - 1
    $variables[$i] = _DateAdd("D", -$i, _NowCalcDate())
Next

_ArrayDisplay($variables)

;now you can call each variable on its own via $variables[X] where X is the row.
;For example:

For $i = 0 to Ubound($variables) - 1
    MsgBox(0, '', 'Variable $variables[' & $i & ']='&$variables[$i])
Next
Posted (edited)

 

Here is an example:

#include <Date.au3>
#include <Array.au3>

Dim $variables[7]

For $i = 0 To Ubound($variables) - 1
    $variables[$i] = _DateAdd("D", -$i, _NowCalcDate())
Next

_ArrayDisplay($variables)

;now you can call each variable on its own via $variables[X] where X is the row.
;For example:

For $i = 0 to Ubound($variables) - 1
    MsgBox(0, '', 'Variable $variables[' & $i & ']='&$variables[$i])
Next

 

Oh thanks!

I will test this, really thanks, i appreciate!

EDIT: This Works!!!! This "_ArrayDisplay" function is so good! Really thanks!

I can't give you a like because "You have reached your quota of positive votes for the day", sorry.

Edited by Chiitus

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
×
×
  • Create New...