Sign in to follow this  
Followers 0
KnowledgeSponge

Regarding Arrays

4 posts in this topic

I'm having a problem with a certain aspect of arrays. I've tried to figure this out through trial and error but not figuring it out. Probably overlooking something but need a little help.

I am trying to declare a variable, say $number, through an inputbox (eg. How many of these do you want?) and then set the total for the array to that number. Then, I want each individual part eg $array[1] $array[2] to start declaring themselves through input boxes till it = $number. But i do not want to have to declare each part of the array myself to keep it open ended. I tried something like this

$values = 0;
$number = InputBox("blah", "How many of these do you want?")
$var1 = $number;
Dim $array[$var1]
$var1 = 0;
While $values = 0;
Do
$array[$var1] = InputBox("Hrmm", "Set this value.")
$var1 = $var1 + 1;
Until $var1 = $number;
WEnd

I just wrote it off the top of my head there cause i deleted what i had cause I couldn't get it to work so that might not be exactly right but you get the idea of what I'm trying to do from that. The prob is that it tries to set $array and $var to whatever the inputbox is which is not allowed and not what I want to happen anyways. I want each individual array to create itself and be declared in the inputbox so that the amount of times it could run would be exponential. Please let me know what I am missing in the equation here. Thanks for your help.

Share this post


Link to post
Share on other sites



this works;

$values = 0;
$number = InputBox("blah", "How many of these do you want?")
Dim $array[$number]
$var1 = 0;
While $values = 0;
   while $var1 < $number
      $array[$var1] = InputBox("Hrmm", "Set this value.")
      $var1 = $var1 + 1;
   wend
WEnd

I would put an error check in for bad input.

$values = 0;
while 1
$number = int(InputBox("blah", "How many of these do you want?"))
if $number>0 then exitloop
wend
Dim $array[$number]
$var1 = 0;
While $values = 0;
   while $var1 < $number
      $array[$var1] = InputBox("Hrmm", "Set this value.")
      $var1 = $var1 + 1;
   wend
WEnd

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Another version of this would use the FOR loop.

$number = InputBox("How many of these do you want?", "InputBox Test")
If IsNumber($Number) Then 
   Dim $array[$number]
   For $value = 0 To $Number-1
     $array[$value] = InputBox("What is entry number " & $value & "?", "InputBox Test")
   Next
Else
    MsgBox(0,"Invalid Entry", "That was not a valid number.")
EndIf

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Thank you for the help guys. There is quite a bit of syntax I am unfamiliar with and trying to absorb by example and you are furthering my efforts. It's appreciated.

Share this post


Link to post
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
Sign in to follow this  
Followers 0