AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Arrays and Lists

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
leggah



Joined: 14 Oct 2007
Posts: 44

PostPosted: Thu Jan 31, 2008 5:21 am    Post subject: Arrays and Lists Reply with quote

Hey,

I'm on and off AHK but recently needed to create something involving lists and arrays. I searched around the site but couldn't really find what I needed.

All I want to do is create a list a-z and access the letters stored in the list.

Basically,

[a,b,c,d,e,f,g..z]

How would I go about creating that array and getting the 5th element out of it or something?

A link to a tutorial I might have missed or code would be fine. Thanks

-leg
_________________
http://bux.to/?r=legault
Back to top
View user's profile Send private message AIM Address
ManaUser



Joined: 24 May 2007
Posts: 906

PostPosted: Thu Jan 31, 2008 5:42 am    Post subject: Reply with quote

There's more than one way to do it of course, but here's a quick example:
Code:
WholeArray := "abcdefghijklmnopqrstuvwxyz"
Loop Parse, WholeArray
   Array%A_Index% := A_LoopField

MsgBox %Array5%
i = 3
MsgBox % Array%i%

That should display "e" and then "c".

Here's what the help file has to say about arrays in general, in case you haven't read that:
http://www.autohotkey.com/docs/misc/Arrays.htm
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu Jan 31, 2008 5:42 am    Post subject: Reply with quote

Here is a common method using a pseudo-array

Code:
Loop 26
  Element%A_Index% := Chr( 65+A_Index-1 )

Loop {
 Random, RND, 1, 26
 MsgBox, 0, % "Element " RND, % Element%RND%


My preferred method to achieve the same result would be:

Code:
Chrs    := "ABCDEFGHIJKLMNOPQRSTUVXYZ"

Loop {
 Random, RND, 1, 26
 MsgBox, 0, Element %RND%, % Chr( NumGet(Chrs,RND-1,"UChar") )


Smile
Back to top
View user's profile Send private message
leggah



Joined: 14 Oct 2007
Posts: 44

PostPosted: Thu Jan 31, 2008 6:29 am    Post subject: Reply with quote

mmm Looks like string parsing rather than lists, but as long as it works xD

Thanks MU, Skan

-leg
_________________
http://bux.to/?r=legault
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group