Jump to content

Declaring arrays.


Recommended Posts

Hey,

I'm kind of new to arrays and I'm trying to declare it at the start of my script so that my Case statement wont error out. I get errors like telling me it's exceeded the variables subscript. How do I declare arrays like $Hello[1] so that if I have a case statement like Case $Hello[1] = "Yes" I won't get an error if $Hello[1] wasn't been set.

I've checked the helpfile...

Link to comment
Share on other sites

  • Moderators

Hey,

I'm kind of new to arrays and I'm trying to declare it at the start of my script so that my Case statement wont error out. I get errors like telling me it's exceeded the variables subscript. How do I declare arrays like $Hello[1] so that if I have a case statement like Case $Hello[1] = "Yes" I won't get an error if $Hello[1] wasn't been set.

I've checked the helpfile...

Learn the functionality of ReDim/UBound or cheat and use _ArrayAdd Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

No. That's not what I need.

My code is similar to...

Dim $Command[2]

;Create GUI

While 1
    ;Declare a few variables
    For $i = 1 To $Command[2]
    Next
    sleep(100)
    WEnd

Try running that, that's the error I get and that's what I'm trying to fix. Sorry, I wasn't very clear.

You're wrong.

That Is what you needed.

For $i = 1 To Ubound($Command) - 1

Unless $Command[2] = an integer.

Also keep in mind, you cannot exceed the limit you propose.

[2] < is the max, Arrays start at 0 (zero), so 0 and 1 are the only two elements you can use without exceeding the array elements.

Edit:

Example:

Dim $Command[2]

2 is the Max elements I can use.

[0] = 1st Element

[1] = 2nd Element

[2] = 3rd Element = Exceeding element size

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You're wrong.

That Is what you needed.

For $i = 1 To Ubound($Command) - 1

Unless $Command[2] = an integer.

Also keep in mind, you cannot exceed the limit you propose.

[2] < is the max, Arrays start at 0 (zero), so 0 and 1 are the only two elements you can use without exceeding the array elements.

Edit:

Example:

Dim $Command[2]

2 is the Max elements I can use.

[0] = 1st Element

[1] = 2nd Element

[2] = 3rd Element = Exceeding element size

Sorry and thank you. :D
Link to comment
Share on other sites

Sorry for the double post...

Thanks for fixing the array error, but now it won't read what I want it to. Below is an example in notepad (type some text into notepad, ie Hello*Test and it should read the Test.)

Dim $ReadCommand[5]
Dim $Command[5]
$Title = "Untitled - Notepad"
$Text = ControlGetText($Title, "", "Edit1")
$Command = StringSplit($Text, "*")
    For $i = 1 To Ubound($Command, 2) - 1
        $ReadCommand = StringSplit($Command[2], @CR)
    Next
MsgBox(64, "Text read after the *", $ReadCommand[1])
Edited by Delta01
Link to comment
Share on other sites

  • Moderators

Sorry for the double post...

Thanks for fixing the array error, but now it won't read what I want it to. Below is an example in notepad (type some text into notepad, ie Hello*Test and it should read the Test.)

Dim $ReadCommand[5]
Dim $Command[5]
$Title = "Untitled - Notepad"
$Text = ControlGetText($Title, "", "Edit1")
$Command = StringSplit($Text, "*")
    For $i = 1 To Ubound($Command, 2) - 1
        $ReadCommand = StringSplit($Command[2], @CR)
    Next
MsgBox(64, "Text read after the *", $ReadCommand[1])
1. Ubound($Command, 2) << You are referencing a 2 dimensional array but you only have a 1 dimensional array.

2. Why are you going to use a "loop" (For/Next) if you are hard coding the split with [2]?

3. http://www.autoitscript.com/forum/index.ph...st&p=295888 is the best I think I can help you now without referring (confusing you) with http://en.wikipedia.org/wiki/Array

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...