Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Help with arrays - assigning values



  • Please log in to reply
3 replies to this topic
Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012
I wish to retrieve the drive letters for various removable storage devices and store them into an array. This is what I designed, but sadly it does not work.
If I plug in a pen drive say F, b is assigned a value F but no value ends up in the array. Please teach me where I'm going wrong.
All help is greatly appreciated.
#Persistent
a:=Object()
DriveGet, drive_list, list, Removable
		loop,10
		{
		b:=SubStr(drive_list,A_Index,1)
                If !b 
                        break
		a.Insert(%b%)
		MsgBox, % array[A_Index]
		MsgBox, %b%
		} 

Using AHK_L 32 bit version on Win7 Ultimate 64 bit.

Thank you.

rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011
You are mixing command and expression syntax, a common problem.
#Persistent
a:=Object()
DriveGet, drive_list, list, Removable
		loop,10
		{
		b:=SubStr(drive_list,A_Index,1)
                If !b 
                        break
		[color=#FF0000]a.Insert(b)[/color]   ; No need for %% here
		[color=#FF0000]MsgBox, % a[A_Index][/color]   ; I think this is what you ment
		MsgBox, %b%
		} 

My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
✓  Best Answer
You might not be using the list from DriveGet in the most optimal fashion either:

[color=#000080]#Persistent
a:=Object()
DriveGet, drive_list, list, Removable
[color=#FF0000]Loop, parse, drive_list[/color]
{
	a.Insert([color=#FF0000]A_LoopField[/color])
	MsgBox, , Array, %	a[A_Index]
	MsgBox, , List, [color=#FF0000]%A_LoopField%[/color]
}[/color]


Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012
Impressive. Thanks @ sinkfaze
and rbrtryn

Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.