Jump to content

Not receiving Return Value ( prob something stupid ive done...


Recommended Posts

Ok i made a function to find a default folder like this

I call it like this

Local $nMsg = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
_FindDefault()
;~ $sDefault = "D:\Code\Projects\"
RegWrite("HKEY_CURRENT_USER\Software\Rand", "Location", "REG_SZ", $sDefault)
EndSwitch
WEnd

Func _FindDefault()
#region $sFindDefault
Local $sDefault = ""
$sDefault = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
If @error = 1 Then ; User cancel or X close error check
MsgBox(48, "Cancelled", "Cancelled By User", 4)
$sDefault = ""
EndIf
If DriveSpaceTotal($sDefault) = 0 Then ; Drive contains no files error check
MsgBox(48, "Source Error", "There Is No Data On That Drive", 4)
$sDefault = ""
EndIf
Local $sDefaultEnd = StringRight($sDefault, 1)
If $sDefaultEnd <> "\" Then $sDefault = $sDefault & "\" ;make sure backslash is on the end
ConsoleWrite("Default = " & $sDefault & @CRLF) ;######## Checking ########
Return $sDefault
#endregion
EndFunc ;==>_FindDefault

When it uses the function _FindDefault() it never completes the reg key

Yet if i use this $sDefault = "D:\Code\Projects\" it works perfectly..

What did i miss?

Many thanks

Link to comment
Share on other sites

Ok i made a function to find a default folder like this

I call it like this

Local $nMsg = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
_FindDefault()
;~ $sDefault = "D:\Code\Projects\"
RegWrite("HKEY_CURRENT_USER\Software\Rand", "Location", "REG_SZ", $sDefault)
EndSwitch
WEnd

Func _FindDefault()
#region $sFindDefault
Local $sDefault = ""
$sDefault = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
If @error = 1 Then ; User cancel or X close error check
MsgBox(48, "Cancelled", "Cancelled By User", 4)
$sDefault = ""
EndIf
If DriveSpaceTotal($sDefault) = 0 Then ; Drive contains no files error check
MsgBox(48, "Source Error", "There Is No Data On That Drive", 4)
$sDefault = ""
EndIf
Local $sDefaultEnd = StringRight($sDefault, 1)
If $sDefaultEnd <> "\" Then $sDefault = $sDefault & "\" ;make sure backslash is on the end
ConsoleWrite("Default = " & $sDefault & @CRLF) ;######## Checking ########
Return $sDefault
#endregion
EndFunc ;==>_FindDefault

When it uses the function _FindDefault() it never completes the reg key

Yet if i use this $sDefault = "D:CodeProjects" it works perfectly..

What did i miss?

Many thanks

You dind't set a variable to store the _FindDefault() return value. And _FindDefault uses $sDefaultEnd as a Local variable so the "Global" $sDefaultEnd used in the RegWrite() will never be touched.

Here is a working example:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Test ME!", 211, 84, 192, 124)
$Button1 = GUICtrlCreateButton("Test ME!", 64, 24, 75, 25)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1
            $sDefault = _FindDefault() ;Set a value to _FindDefault

            If @error Then
                $sDefault = "D:\Code\Projects\"
            EndIf
            RegWrite("HKEY_CURRENT_USER\Software\Rand", "Location", "REG_SZ", $sDefault)
    EndSwitch
WEnd

Func _FindDefault()
    #region $sFindDefault
    Local $sDefault = ""
    $sDefault = FileSelectFolder("Choose a drive.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
    If @error = 1 Then ; User cancel or X close error check
        MsgBox(48, "Cancelled", "Cancelled By User", 4)
        $sDefault = ""
    EndIf
    If DriveSpaceTotal($sDefault) = 0 Then ; Drive contains no files error check
        MsgBox(48, "Source Error", "There Is No Data On That Drive", 4)
        $sDefault = ""
    EndIf
    Local $sDefaultEnd = StringRight($sDefault, 1)
    If $sDefaultEnd <> "\" Then $sDefault = $sDefault & "\" ;make sure backslash is on the end
    ConsoleWrite("Default = " & $sDefault & @CRLF) ;######## Checking ########
    Return $sDefault
    #endregion $sFindDefault
EndFunc   ;==>_FindDefault

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

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