Jump to content

How to learn how to use arrays?


frew
 Share

Recommended Posts

Hello,

I'm not sure where to start with learning how to use arrays.

I think they are important, but I don't know the best way to start using them, or how to best go about learning how to use them in AutoIt.

So if anybody would point me to a tutorial, or some resource on beginning with arrays, I'd be most appreciative.

I mostly want to put many lines of text into an array (ie each line containing a single MouseClick), and then, in all kinds of diverse ways, rearrange the order in which the MouseClicks occur. I thought arrays might be helpful.

Thanks for any ideas, and for any array practices I can work on.

frew

Link to comment
Share on other sites

Thanks for the link Andreik.

I've gone through that great tutorial by BrettF. What wonderful work.

It touches upon arrays, but now I'm looking for not only how to create them, but for ideas on how to use them.

Like reading files into them, how to access the values in them, tips and tricks for how to really utilize arrays in all kinds of ways.

I sort of want to go more in depth with arrays in order to feel that I can use them effectively when I need to.

Thanks for any other ideas.

frew

Link to comment
Share on other sites

Thanks for the link Andreik.

I've gone through that great tutorial by BrettF. What wonderful work.

It touches upon arrays, but now I'm looking for not only how to create them, but for ideas on how to use them.

Like reading files into them, how to access the values in them, tips and tricks for how to really utilize arrays in all kinds of ways.

I sort of want to go more in depth with arrays in order to feel that I can use them effectively when I need to.

Thanks for any other ideas.

frew

An array is basically a matrix of information. It has rows and collumns, every element has some information, it could be text or a number or something else.

If you want to experiment with arrays start with the Array UDF and check some stuff like filereadfromarray and filewritefromarray.

Link to comment
Share on other sites

A simple example to use arrays:

Read a file in one array, display this array and then get some random lines from array.

#include <File.au3>
#include <Array.au3>
$SELECT = FileOpenDialog("SELECT",@ScriptDir,"Text (*.txt)",1)
Dim $ARRAY
_FileReadToArray($SELECT,$ARRAY)
_ArrayDisplay($ARRAY)
For $I = 1 To 5
    $RANDOM = Random(1,$ARRAY[0],1)
    MsgBox(0,"Line#" & $RANDOM,$ARRAY[$RANDOM])
Next

When the words fail... music speaks.

Link to comment
Share on other sites

Okay thanks Qousio.

I got this to work:

#Include <File.au3>
#Include <Array.au3>

Dim $aArray
_FileReadToArray("C:\array_read_from_this_1.txt", $aArray)

_ArrayDisplay($aArray)

_FileWriteFromArray("C:\array_write_to_this_1.txt", $aArray)

That puts the lines form array_read_from_this_1.txt into an array, and then puts the array into the array_write_to_this_1.txt.

Now I'm wondering how to do stuff with what's now in the array.

If I have hundreds of lines of text in the array_read_from_this_1.txt, and it's all put into an array, I don't know how I'd ever remember what's what inside the array. So I cannot really use the individual elements of the array like I'm used to using individual variables in a script.

Thanks for any other ideas for me to work with.

frew

Link to comment
Share on other sites

Read a file in one array, display this array and then get some random lines from array.

Oh that's a nice idea. Thank so much Andreik.

I'll work with that a bit and see what you did with this.

This gives me some techniques to work with.

Thanks again!

frew

Link to comment
Share on other sites

Just wondering now...

I get some extra lines of text that show up in the file that is read from the array...any idea what these extra lines are?

File that is read into the array:

oneone1

twotwo2

threethree3

fourfour4

fivefive5

After some randomization,

File that is written from the array: (What's the extra '5' that shows up?)

twotwo2

fourfour4

threethree3

fivefive5

5

oneone1

Thanks for any ideas,

frew

Link to comment
Share on other sites

when the "write from array" uses the random numbers "0" is one of them.

In other words $array[0] = 5

Oh, okay, I see. Thank you very much Valuater.

Just curious, is there any way to make the $array[0] not show up in the "write from array" results in the text file that is being written to? That $array[0] kind of gets in the way of the results I want in the text files. I could just edit it out, but with lots of text files like this. with lots of experimenting, etc., it would be nice to just have the $array[0] not show up in the text files that are written to...so I wouldn't have to do all that extra text editing as I go along with tons of testing.

Thanks for any ideas,

frew

Link to comment
Share on other sites

Oh, okay, I see. Thank you very much Valuater.

Just curious, is there any way to make the $array[0] not show up in the "write from array" results in the text file that is being written to? That $array[0] kind of gets in the way of the results I want in the text files. I could just edit it out, but with lots of text files like this. with lots of experimenting, etc., it would be nice to just have the $array[0] not show up in the text files that are written to...so I wouldn't have to do all that extra text editing as I go along with tons of testing.

Thanks for any ideas,

frew

You need to get in the habit of looking that kind of thing up in the help file before posting. Look up _FileWriteFromArray() and read what the $i_Base parameter does.

^_^

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You need to get in the habit of looking that kind of thing up in the help file before posting. Look up _FileWriteFromArray() and read what the $i_Base parameter does.

Your right, I'll do that more. I always go to the helpfile first, but I sometimes miss something, or don't understand what's in the help if it's something I'm just beginning with.

Thanks for directing me to the $i_Base parameter.

Just wondering, I do this

#Include <File.au3>
#Include <Array.au3>


#Include <File.au3>
#Include <Array.au3>
Global $aArray
_FileReadToArray("C:\array_read_from_this_1.txt", $aArray, 1)
_ArrayDisplay($aArray)
_FileWriteFromArray("C:\array_write_to_this_1.txt", $aArray, 1)

and I get this error message

C:\Program Files\AutoIt3\Scripts\Misc\array read write\FileReadToArray_ArrayDisplay_FileWriteFromArray_1.au3(6,61) : ERROR: _FileReadToArray() called with wrong number of args.

_FileReadToArray("C:\array_read_from_this_1.txt", $aArray, 1)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\PROGRAM FILES\AUTOIT3\Include\File.au3(192,49) : REF: definition of _FileReadToArray().

Func _FileReadToArray($sFilePath, ByRef $aArray)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Scripts\Misc\array read write\FileReadToArray_ArrayDisplay_FileWriteFromArray_1.au3 - 1 error(s), 0 warning(s)

whereas without the ', 1' added, the script runs fine but starts at [0].

Thanks for any other ideas. I checked the help, but I still may be overlooking something that's there.

frew

Link to comment
Share on other sites

Your right, I'll do that more. I always go to the helpfile first, but I sometimes miss something, or don't understand what's in the help if it's something I'm just beginning with.

Thanks for directing me to the $i_Base parameter.

Just wondering, I do this

#Include <File.au3>
#Include <Array.au3>


#Include <File.au3>
#Include <Array.au3>
Global $aArray
_FileReadToArray("C:\array_read_from_this_1.txt", $aArray, 1)
_ArrayDisplay($aArray)
_FileWriteFromArray("C:\array_write_to_this_1.txt", $aArray, 1)

and I get this error message

C:\Program Files\AutoIt3\Scripts\Misc\array read write\FileReadToArray_ArrayDisplay_FileWriteFromArray_1.au3(6,61) : ERROR: _FileReadToArray() called with wrong number of args.
_FileReadToArray("C:\array_read_from_this_1.txt", $aArray, 1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\PROGRAM FILES\AUTOIT3\Include\File.au3(192,49) : REF: definition of _FileReadToArray().
Func _FileReadToArray($sFilePath, ByRef $aArray)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Program Files\AutoIt3\Scripts\Misc\array read write\FileReadToArray_ArrayDisplay_FileWriteFromArray_1.au3 - 1 error(s), 0 warning(s)

whereas without the ', 1' added, the script runs fine but starts at [0].

Thanks for any other ideas. I checked the help, but I still may be overlooking something that's there.

frew

OK, you looked up _FileWriteFromArray() and found a new parameter to use.

Now, look up _FileReadToArray() and see what the parameters are...

^_^

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Now, look up _FileReadToArray() and see what the parameters are...

Yep, I should have done that. Okay, now I've got it. Thanks so much for your help PsaltyDS.

#Include <File.au3>

#Include <Array.au3>

Global $aArray

_FileReadToArray("C:\array_read_from_this_1.txt", $aArray)

_ArrayDisplay($aArray)

_FileWriteFromArray("C:\array_write_to_this_1.txt", $aArray, 1)

_ArrayDisplay($aArray)

frew

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