Sign in to follow this  
Followers 0
myk3

Loop to add combo boxes from array list

5 posts in this topic

I can not figure this out for the life of me.. I know it is simple but I just need fresh eyes on it i think..

I am pulling the fixed disk using

$var = DriveGetDrive( "FIXED" )

I am trying to add a combo box with each item in the array into it.. but also add a new combo box for each item in the array then add the items from the array into the combo box..

so for example my array has "C:|D:|Z:"

i should have 3 combo boxes with C: D: and Z: as options

here is what i am using.. but if there is more than 4 fixed drives (or partitions) then it will stop at 4.

$var = DriveGetDrive( "FIXED" )
If NOT @error Then
For $i = 1 to $var[0]
  $Drive = GUICtrlCreateCombo("", 242, 175, 145, 25)
  GuiCtrlSetData($Drive, "|" & _ArrayToString($var, "|", 1))
Next
if ubound($var)-1 > 1 then
For $i = 1 to $var[0]
  $Drive1 = GUICtrlCreateCombo("", 242, 200, 145, 25)
  GuiCtrlSetData($Drive1, "|" & _ArrayToString($var, "|", 1))
Next
endif
if ubound($var)-1 > 2 then
For $i = 1 to $var[0]
  $Drive1 = GUICtrlCreateCombo("", 242, 225, 145, 25)
  GuiCtrlSetData($Drive1, "|" & _ArrayToString($var, "|", 1))
Next
endif
if ubound($var)-1 > 3 then
For $i = 1 to $var[0]
  $Drive1 = GUICtrlCreateCombo("", 242, 250, 145, 25)
  GuiCtrlSetData($Drive1, "|" & _ArrayToString($var, "|", 1))
Next
endif
EndIf

Share this post


Link to post
Share on other sites



I just wrote a little script using DriveGetDrive and discovered that using "Fixed" did not work for me. Using "All" worked perfectly. So, my suggestion is to change Fixed to All. Here's my script (it returns an array of all your drive letters):

#include <Array.au3>
 
$driveList = DriveGetDrive("All")
Dim $list[$driveList[0]]
 
Global $i = 0
For $j = 65 To 90 Step 1
    $tempDriveLetter = Chr($j)
    DriveGetType($tempDriveLetter & ":\")
    If NOT @error Then
        $list[$i] = $tempDriveLetter
        $i += 1
    EndIf
Next
 
_ArrayDisplay($list)

#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well you go me started on the right path..

$drives = DriveGetDrive("All")

returns an arrary of all the drive letters on your system

$drives = DriveGetDrive("FIXED")

returns an arrary of all the fixed disk drive letters on your system (C: for most cases)

Here is what i am using and it does what I need it to do..

$driveList = DriveGetDrive("all")
$loc = 175
$inc = 0
Global $i = 0
For $j = UBound($driveList)-1 to 1 step -1
    If NOT @error Then
        for $p = UBound($driveList)-1 to 1 step -1
                $Drive[$p] = GUICtrlCreateCombo("", 242, $loc + $inc, 145, 25)
                GuiCtrlSetData($Drive[$p], "|" & _ArrayToString($driveList, "|", 1))
        next
        $inc += 25
        $i += 1
    EndIf
Next

Thanks for the help..

Edited by myk3

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You have me a little confused, DriveGetDrive("All") returns 5 drives on my PC, so I get five sets ($j) of five comboboxes ($p) stacked on top of each other, twenty-five comboboxes in all.. Your @error test probably needs to be right after the DriveGetDrive, rather than testing the result of a UBound() statement. You can dispense with the UBound() statements altogether as DriveGetDrive() already returns the drive count in element 0, and you probably only need to execute _ArrayToString() once? Maybe:

Global $Drive[10]
$aDriveList = DriveGetDrive("All") ; drives array
If @error Then
MsgBox(1,"","No drives found")
Exit
EndIf
$sDriveList = _ArrayToString($driveList, "|", 1) ; drives string
for $p = 1 to $driveList[0]
    $Drive[$p] = GUICtrlCreateCombo("", 242, 175 + $p * 25, 145, 25)
    GuiCtrlSetData($Drive[$p], "|" & $sDriveList)
Next
Edited by Spiff59

Share this post


Link to post
Share on other sites

Yea i just saw the $j was running through and overwriting the comboboxes for me..

I changed it to this..

$driveList = DriveGetDrive("fixed")
$loc = 175
$inc = 0
 
for $p = UBound($driveList)-1 to 1 step -1
            $Drive[$p] = GUICtrlCreateCombo("", 242, $loc + $inc, 145, 25)
            GuiCtrlSetData($Drive[$p], "|" & _ArrayToString($driveList, "|", 1))
            $inc += 25
next
$inc = 0

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