Jump to content

Need some help with variables.


Asamoya
 Share

Recommended Posts

Firstly, heres an example bit of code.

If $o = $n Then
  Call ("TIGER")
  Return
Else
  Send ($textarray0[2])
  Send ("{TAB}")
  Send ("{TAB}")
  Send ($textarray0[1])
  Send ("{TAB}")
EndIf
$o = $o +1
If $o = $n Then
  Call ("TIGER")
  Return
Else
  Send ($textarray1[2])
  Send ("{TAB}")
  Send ("{TAB}")
  Send ($textarray1[1])
  Send ("{TAB}")
EndIf
$o = $o +1
If $o = $n Then
  Call ("TIGER")
  Return
Else
  Send ($textarray2[2])
  Send ("{TAB}")
  Send ("{TAB}")
  Send ($textarray2[1])
  Send ("{TAB}")
EndIf
$o = $o +1
If $o = $n Then
  Call ("TIGER")
  Return
Else
  Send ($textarray3[2])
  Send ("{TAB}")
  Send ("{TAB}")
  Send ($textarray3[1])
  Send ("{TAB}")
EndIf

I was wondering, is there any way to shorten this code to something like this:

While 1
If $o = $n Then
Call ("TIGER")
Return
Else
Send ($textarray$o[2])
Send ("{TAB}")
Send ("{TAB}")
Send ($textarray$o[1])
Send ("{TAB}")
EndIf
$o = $o +1
WEnd

i.e. so the function changes based on the value of $o, without having to do the long bit of code for $textarray0 $textarray1 $textarray2 $textarray3 etc as in shown in the first code box.

Hope I explained it clearly :/

Link to comment
Share on other sites

It looks like what you want is a two dimensional array, with an x and y coordinate, such as:

Dim $textarray[3][3]

...

For $o = 1 to 2

If $o = $n Then
Call ("TIGER")
Return
Else
Send ($textarray[$o][2])
Send ("{TAB}")
Send ("{TAB}")
Send ($textarray[$o][1])
Send ("{TAB}")
EndIf

Next
Edited by VeryGary
Link to comment
Share on other sites

Hm, I'm trying VeryGary's solution, but have run into a problem

Is it possible to populate a row of an array with stringsplit?

What im trying and getting an error (well not an error, just the $textarray array contains no data):

$textarray[0] = StringSplit ($gettext[0], " ", 1)

What I want to get is:

$textarray[0][0] = index number

$textarray[0][1] = string part 1

$textarray[0][2] = string part 2.

Link to comment
Share on other sites

While 1
If $o = $n Then
  Call ("TIGER")
  ExitLoop
Else
  Send ($textarray0[2])
  Send ("{TAB}")
  Send ("{TAB}")
  Send ($textarray0[1])
  Send ("{TAB}")
EndIf
$o += 1
WEnd

Thanks for replying, with your code the variable stays as $textarray0 for each loop. In my script, the variable needs to change with each run of the loop i.e. $textarray0 -> $textarray1 -> $textarray2 etc. Hence the attempt to include $o in the variable.
Link to comment
Share on other sites

Thanks for replying, with your code the variable stays as $textarray0 for each loop. In my script, the variable needs to change with each run of the loop i.e. $textarray0 -> $textarray1 -> $textarray2 etc. Hence the attempt to include $o in the variable.

Of course, my mistake.

You can put your $textarrays into another array, and increment it to get around that.

eg

$aatextarray[5] = [$textarray0,$textarray1,$textarray2,$textarray3,$textarray4]
$count = 0
While 1
Local $myarray = $aatextarray[$count]
If $o = $n Then
  Call ("TIGER")
  ExitLoop
Else
  Send ($myarray[2])
  Send ("{TAB}")
  Send ($myarray[1])
  Send ("{TAB}")
  Send ("{TAB}")
EndIf
$o += 1
$count += 1
WEnd
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Here, let me try to explain myself a bit clearer. This is what you're getting at Asamoya, ya?

For $o = 1 To 3
    ConsoleWrite("$textarray" & $o & @LF)
Next

Edit: Again, this is pretty much the same as JohnOne's example. In that it's just another way of doing the same thing.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Here, let me try to explain myself a bit clearer. This is what you're getting at Asamoya, ya?

For $o = 1 To 3
    ConsoleWrite("$textarray" & $o & @LF)
Next

Edit: Again, this is pretty much the same as JohnOne's example. In that it's just another way of doing the same thing.

Hi somdcomputerguy, I'm quite sure that this is not possible, you can write to console the name if that variable

like that, but you cannot write to console the contents of the array that the variable is, or indeed the contents

of a non array variable.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi somdcomputerguy, I'm quite sure that this is not possible, you can write to console the name if that variable

like that, but you cannot write to console the contents of the array that the variable is, or indeed the contents

of a non array variable.

I see what you're saying. I was under the impression that Asamoya had the variables $textarea1, $textarea2, & $textarea3 already, but wanted to process them without writing three separate, similar, blocks of code. I used the ConsoleWrite just to display the For..Next loop changing the variable.

Is it possible to populate a row of an array with stringsplit?

This might work..

$Variable = StringSplit ($gettext[0], " ", 1)

$textarray[0][$Variable[1]]
$textarray[0][$Variable[2]]
$textarray[0][$Variable[3]]

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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