Sign in to follow this  
Followers 0
Zenith

Send Command with arrays

6 posts in this topic

On a normal basis I dislike asking for help since google and searching should solve most of my problems, along with the fact that this will be my first post therefore looking like a idiot.... but... there was no luck in searching google or this forum.. So on with my problem...

I'm getting better at autoit and C/C++ but I'm still learning.... So I created this number guessing game with C++, nothing hard. Yes I can make it guess it self with C++, but that would be no fun. So on the learning side of autoit, I was going to make it guess the number. (I was planning to upgrade this to hangman if I figure this one out.)

Local $arr[5] = ["1","2","3","4","5"]
For $i = 0 to 5 ;looping
Send($arr[$i] )         ; Guess
Send("{ENTER}") ; Guess
Sleep(100)
Next

Problem is that when I run it, it doesn't hit anything/type. (If anyone says just Copy paste "Send(1 to 5), Enter : I will slap you, because that's the cheaters way out, I want to make this efficient! ;) )

Would I have to maybe covert the elements in the array to a string and have it type that? Any help is appreciated!

---A Learning Coder---

Share this post


Link to post
Share on other sites



There's nothing wrong with that script, except that "Array variable has incorrect number of subscripts or subscript dimension range exceeded." error. Didn't you even run the script once before posting it?

Anyway, the error is because you're trying the read the sixth element (remember that arrays start at 0).

This works:

Local $arr[5] = ["1","2","3","4","5"]
For $i = 0 to 4 ;looping
    ConsoleWrite($arr[$i] & @CRLF)
Next

If the array may ever change then use UBound() to get the arrays size instead of hard-coding it.

Local $arr[5] = ["1","2","3","4","5"]
For $i = 0 to UBound($arr) -1 ;looping
    ConsoleWrite($arr[$i] & @CRLF)
Next

And lastly, if you feel insecure with arrays in any way, try the Array tutorial on th wiki, and don't forget to check the helpfile!

;)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Uh, that was an excerpt from the main one, the main is slightly more... messy... Which included hooking of keyboard and mouse. And I shortened the for loop and array from 10, Silly error on my part. Is there a way to have it "hit" the key though? Like Send() will send whatever is in quotes to what ever window that is current.

Edited by Zenith

Share this post


Link to post
Share on other sites

Of course it doesn't ... because it is exiting with an error ;)

You didn't pay attention to the output?

Your array has 5 elements and you are running the loop for 6 (0 to 5 = 6); that's the error, you are trying to use $arr[5] which doesn't exist.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Uh, that was an excerpt from the main one, the main is slightly more... messy... Which included hooking of keyboard and mouse. And I shortened the for loop and array from 10, Silly error on my part. Is there a way to have it "hit" the key though? Like Send() will send whatever is in quotes to what ever window that is current.

Change the ConsoleWrite() from what I posted to a Send() and you will see that it works just fine and posts all 5 numbers. Just like your script, the only difference is that your crashes.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Much thanks, I'll now transform into a lurker. ;)

EDIT: I ran the sample script as part of the main code, did nothing. Me trusting you guys, assuming you're right and I'm wrong, ran the code separately. Worked like a charm. So i know something's up with my hooking...

Edited by Zenith

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