Jump to content

Return in Loop


Recommended Posts

Hey,

I have a problem, i am a bit confused  >_<

I try to add this information about the drives into a combobox, and return the array.

Func ListDrives()
        $AllDrive = DriveGetDrive("ALL")
        For $X = 1 to UBound($AllDrive) -1
            $CurrentDrive = $AllDrive[$X]
            Return ($CurrentDrive & '\' & ' - ' & DriveGetType($CurrentDrive) & @LF)
        Next
EndFunc

So that I can later add the information just by calling the func:

_GUICtrlComboBox_AddString($Combo1, ListDrives())

But only the first drive appears in the combobox O.o

Link to comment
Share on other sites

You're returning in the middle of your loop, it's never going to finish, so you're never going to get the rest of the information you want.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Func ListDrives()
        Local $AllDrive = DriveGetDrive("ALL")
        Local $DriveInfo[99]
        For $X = 1 to UBound($AllDrive) -1
            $CurrentDrive = $AllDrive[$X]
            $DriveInfo[$X] =  ($CurrentDrive & '\' & ' - ' & DriveGetType($CurrentDrive) & @LF)
        Next
        Return $DriveInfo
EndFunc

tried now outside same problem...

Link to comment
Share on other sites

  • Developers

That works fine and will return the array. so what is your problem?

Have you done any debugging yourself what is happening?

Hint: Should the udf really return an array or should  $DriveInfo 's content be differently?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Your first attempt only returned the first string, your second attempt returns an array and there's no possible way it could be having the same problem. _GUICtrlComboBox_AddString wouldn't do anything with the returned array, your combo will be empty.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I just want to call the function and add the information into a combobox (without having the combobox_addstrign routine in the function).

So I just want to call it like this:

_GUICtrlComboBox_AddString($Combo1, ListDrives())

And in the combobox it should look like this:

C: - Fixed

D: - Fixed

E: - CDROM

I: - Removable

etcetc...

Link to comment
Share on other sites

try like this and call this function passing the combo reference to be filled:

Func ListDrives($hCombo)
    $AllDrive = DriveGetDrive("ALL")
    For $X = 1 To UBound($AllDrive) - 1
        ; $CurrentDrive = $AllDrive[$X]
        ; Return ($CurrentDrive & '\' & ' - ' & DriveGetType($CurrentDrive) & @LF)
        $AllDrive[$X] &= '\' & ' - ' & DriveGetType($AllDrive[$X])
        _GUICtrlComboBox_AddString($hCombo, $AllDrive[$X])
    Next
EndFunc   ;==>ListDrives

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

You can't add it like that, the UDF function takes a string, and your function returns an array.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers

I just want to call the function and add the information into a combobox (without having the combobox_addstrign routine in the function).

So I just want to call it like this:

_GUICtrlComboBox_AddString($Combo1, ListDrives())

And in the combobox it should look like this:

C: - Fixed

D: - Fixed

E: - CDROM

I: - Removable

etcetc...

The point is that I am trying to get you to start figuring things out for yourself in stead of posting constantly these questions.

It is clear what you want but you are really posting a lot of questions where it seems you are not trying much to understand things first and figuring out what could be the issue.

Teach ... fish ... etc  ;)

So, answer this question: How should the returned value look from ListDrives() ?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The point is that I am trying to get you to start figuring things out for yourself in stead of posting constantly these questions.

It is clear what you want but you are really posting a lot of questions where it seems you are not trying much to understand things first and figuring out what could be the issue.

Teach ... fish ... etc  ;)

So, answer this question: How should the returned value look from ListDrives() ?

Jos

The returned value is an array?

Link to comment
Share on other sites

  • Developers

The returned value is an array?

What should the Func return ... or in other words: How should the value look that contains the "?????" : _GUICtrlComboBox_AddString($Combo1, "????")

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

The ???? should be the name of the function which retruns me the array of the drives?

No, What exactly should it exactly contain to show what you want?

Show it!

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The func returns an array, and you need a string to populate the combo ...

#include <GUIConstantsEx.au3>
#include <Array.au3>

GUICreate("My GUI combo") 
GUICtrlCreateCombo("drives", 10, 10)
GUICtrlSetData(-1, ListDrives(), "") 
GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func ListDrives()
        Local $AllDrive = DriveGetDrive("ALL")
        Local $DriveInfo[$AllDrive[0]]
        For $X = 1 to $AllDrive[0]
            $CurrentDrive = $AllDrive[$X]
            $DriveInfo[$X-1] =  ($CurrentDrive & '\' & ' - ' & DriveGetType($CurrentDrive))
        Next
        Return _ArrayToString($DriveInfo, "|")
EndFunc
Link to comment
Share on other sites

  • Developers
_GUICtrlComboBox_AddString($Combo1,ListDrives())

?

No..  this question cannot be this difficult to answer:  What should the string look like that  ListDrives() should return?

So change the "?????" to the exact text that needs to be returned.

_GUICtrlComboBox_AddString($Combo1,"??????")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Local $aArray = DriveGetDrive("ALL")
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox($MB_SYSTEMMODAL, "", "It appears an error occurred.")
Else
    For $i = 1 To $aArray[0]
        ; Show all the drives found and convert the drive letter to uppercase.
        MsgBox(0, "", "Drive " & $i & "/" & $aArray[0] & ":" & @CRLF & StringUpper($aArray[$i]))
    Next
EndIf

problem?

C0d3 is P0etry( ͡° ͜ʖ ͡°)

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