l3ill Posted December 19, 2013 Posted December 19, 2013 I have been using this little GUI for some time now, succesfully I might add. And was getting ready to post it as a snippet so I cleaned it up a bit and tested it and lo and behold a little mistake. After clicking the Clear button which deletes the ini and clears the controls of any login information, the test connection still connects.I have to assume that this means the variables are still carrying the data somehow soI tried setting them all to "" but that didnt work either. Any help is appreciated.Bill expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FTPEx.au3> Local $HostName Local $UserName Local $PassWord Local $testConn $Form1 = GUICreate("FTP Login Credentials", 357, 162, 192, 124) $HostNameB = GUICtrlCreateInput($HostName, 40, 24, 161, 21) $UserNameB = GUICtrlCreateInput($UserName, 40, 56, 161, 21) $PassWordB = GUICtrlCreateInput($PassWord, 40, 88, 161, 21) $Save = GUICtrlCreateButton("Save", 232, 24, 73, 25) GUICtrlSetTip(-1, "Saves login Info to INI File") $Load = GUICtrlCreateButton("Load", 232, 56, 73, 25) GUICtrlSetTip(-1, "Loads Previously Saved login Info from INI File") $clear = GUICtrlCreateButton("Clear", 232, 88, 73, 25) GUICtrlSetTip(-1, "Deletes any Previously saved INI Files") $testConn = GUICtrlCreateButton("Test Connection", 132, 120, 90, 25) GUICtrlSetTip(-1, "Test your Login Credentials") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Load _iniLoad() Case $Save _iniSave() Case $clear _clearAll() Case $testConn _testConn() EndSwitch WEnd Func _clearAll() GUICtrlSetData($HostNameB, "") GUICtrlSetData($UserNameB, "") GUICtrlSetData($PassWordB, "") $iniFile = @ScriptDir & "\login.ini" If FileExists($iniFile) Then FileDelete($iniFile) MsgBox(4096, $iniFile, $iniFile & ": Was Deleted", 2) Else MsgBox(4096, $iniFile, $iniFile & ": Does not Exist", 2) EndIf EndFunc ;==>_clearAll Func _iniLoad() $HostName = IniRead(@ScriptDir & "\login.ini", "login", "HostName", "Default Value") $UserName = IniRead(@ScriptDir & "\login.ini", "login", "UserName", "Default Value") $PassWord = IniRead(@ScriptDir & "\login.ini", "login", "PassWord", "Default Value") GUICtrlSetData($HostNameB, $HostName) GUICtrlSetData($UserNameB, $UserName) GUICtrlSetData($PassWordB, $PassWord) EndFunc ;==>_iniLoad Func _iniSave() $HostName = GUICtrlRead($HostNameB) $UserName = GUICtrlRead($UserNameB) $PassWord = GUICtrlRead($PassWordB) IniWrite(@ScriptDir & "\login.ini", "login", "HostName", $HostName) IniWrite(@ScriptDir & "\login.ini", "login", "UserName", $UserName) IniWrite(@ScriptDir & "\login.ini", "login", "PassWord", $PassWord) EndFunc ;==>_iniSave Func _testConn() Local $hOpen = _FTP_Open('MyFTP Control') Local $hConn = _FTP_Connect($hOpen, $HostName, $UserName, $PassWord) If $hConn = 0 Then MsgBox(0, "FTP Connection", "Connection not possible", 1) EndIf If $hConn > 0 Then MsgBox(0, "FTP Connection", "FTP Connected Successfully", 1) EndIf Local $Ftpc = _FTP_Close($hConn) Local $Ftpo = _FTP_Close($hOpen) EndFunc ;==>_testConn My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
ripdad Posted December 19, 2013 Posted December 19, 2013 The first three vars in the script holds that data, right? "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
l3ill Posted December 19, 2013 Author Posted December 19, 2013 right. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
ripdad Posted December 19, 2013 Posted December 19, 2013 Perhaps a check at the top of _testConn() If $HostName = '' Then Return "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Solution l3ill Posted December 19, 2013 Author Solution Posted December 19, 2013 (edited) Nope, that didn't work Thanks anyway. I did find a workaround by letting it load the default empty values at the end of the _clearAll() function. I guess you have to overwrite them because as mentioned above $HostName = "" didnt work... Still would like to know what the deal was though... Here is the fix for future searchers: Func _clearAll() GUICtrlSetData($HostNameB, "") GUICtrlSetData($UserNameB, "") GUICtrlSetData($PassWordB, "") $iniFile = @ScriptDir & "\login.ini" If FileExists($iniFile) Then FileDelete($iniFile) MsgBox(4096, $iniFile, $iniFile & ": Was Deleted", 2) Else MsgBox(4096, $iniFile, $iniFile & ": Does not Exist", 2) EndIf _iniLoad() EndFunc ;==>_clearAll Edited December 19, 2013 by l3ill My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
ripdad Posted December 19, 2013 Posted December 19, 2013 Or $HostName = '' $UserName = '' $PassWord = '' "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
l3ill Posted December 19, 2013 Author Posted December 19, 2013 tried setting them all to "" but that didnt work $HostName = "" didnt work... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
ripdad Posted December 19, 2013 Posted December 19, 2013 expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FTPEx.au3> Local $HostName Local $UserName Local $PassWord $Form1 = GUICreate("FTP Login Credentials", 357, 162, 192, 124) $HostNameB = GUICtrlCreateInput($HostName, 40, 24, 161, 21) $UserNameB = GUICtrlCreateInput($UserName, 40, 56, 161, 21) $PassWordB = GUICtrlCreateInput($PassWord, 40, 88, 161, 21) $Save = GUICtrlCreateButton("Save", 232, 24, 73, 25) GUICtrlSetTip(-1, "Saves login Info to INI File") $Load = GUICtrlCreateButton("Load", 232, 56, 73, 25) GUICtrlSetTip(-1, "Loads Previously Saved login Info from INI File") $clear = GUICtrlCreateButton("Clear", 232, 88, 73, 25) GUICtrlSetTip(-1, "Deletes any Previously saved INI Files") $testConn = GUICtrlCreateButton("Test Connection", 132, 120, 90, 25) GUICtrlSetTip(-1, "Test your Login Credentials") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Load _iniLoad() Case $Save _iniSave() Case $clear _clearAll() Case $testConn _testConn() EndSwitch WEnd Func _clearAll() GUICtrlSetData($HostNameB, "") GUICtrlSetData($UserNameB, "") GUICtrlSetData($PassWordB, "") $iniFile = @ScriptDir & "\login.ini" If FileExists($iniFile) Then FileDelete($iniFile) MsgBox(4096, $iniFile, $iniFile & ": Was Deleted", 2) Else MsgBox(4096, $iniFile, $iniFile & ": Does not Exist", 2) EndIf $HostName = "" $UserName = "" $PassWord = "" EndFunc ;==>_clearAll Func _iniLoad() $HostName = IniRead(@ScriptDir & "\login.ini", "login", "HostName", "") $UserName = IniRead(@ScriptDir & "\login.ini", "login", "UserName", "") $PassWord = IniRead(@ScriptDir & "\login.ini", "login", "PassWord", "") GUICtrlSetData($HostNameB, $HostName) GUICtrlSetData($UserNameB, $UserName) GUICtrlSetData($PassWordB, $PassWord) EndFunc ;==>_iniLoad Func _iniSave() $HostName = GUICtrlRead($HostNameB) $UserName = GUICtrlRead($UserNameB) $PassWord = GUICtrlRead($PassWordB) IniWrite(@ScriptDir & "\login.ini", "login", "HostName", $HostName) IniWrite(@ScriptDir & "\login.ini", "login", "UserName", $UserName) IniWrite(@ScriptDir & "\login.ini", "login", "PassWord", $PassWord) EndFunc ;==>_iniSave Func _testConn() If $HostName = "" Then Return Local $hOpen = _FTP_Open('MyFTP Control') Local $hConn = _FTP_Connect($hOpen, $HostName, $UserName, $PassWord) If $hConn = 0 Then MsgBox(0, "FTP Connection", "Connection not possible", 1) EndIf If $hConn > 0 Then MsgBox(0, "FTP Connection", "FTP Connected Successfully", 1) EndIf Local $Ftpc = _FTP_Close($hConn) Local $Ftpo = _FTP_Close($hOpen) EndFunc ;==>_testConn "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
l3ill Posted December 19, 2013 Author Posted December 19, 2013 ripdad - That causes the GUI not to function properly anymore. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
ripdad Posted December 19, 2013 Posted December 19, 2013 In what way? I might have been a bit presumptuous on your _iniLoad() function. Are you placing real login data on the IniRead, 4th parameter, in the event the ini doesn't exist? If you are, thats should be easy to fix. Anyways, I gotta run, good luck to you. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now