Inpho Posted July 2, 2016 Posted July 2, 2016 Hi all, again So, this code, I got no idea what's going on. The function _CPUploadFiles returns a file. The first msgbox in the ActionHandler shows that the variable contains the correct filename, but it will always end up in the wrong part of the if statement. Am I going mad? Func _CPActionHandler($_iAHArrayRow, $_iAHArrayCol) Local $_sAHLocalFile, $_sAHRemoteFile If $_iAHArrayCol = 0 Then Switch $_iAHArrayRow Case 1 $_sAHLocalFile = _CPUploadFiles() MsgBox(0, "", $_sAHLocalFile) ClipPut($_sAHLocalFile) If $_sAHLocalFile = 0 Then MsgBox(0, "wat", $_sAHLocalFile) Return (0) Else $_sAHRemoteFile = $_sAHLocalFile MsgBox(0, $_sAHLocalFile, $_sAHRemoteFile) ProgressOn("Upload Progress", $_sAHLocalFile) _FTP_ProgressUpload ( $hFTPConnectSession, $_sAHLocalFile, "/" & $_sAHRemoteFile, _UpdateProgress) ProgressOff() ;_FTP_ProgressUpload ( $hFTPConnectSession, $_sAHFile, "/Scripts/test2/" & $_sAHFile, _UpdateProgress) $aa = @error MsgBox(0, "", $aa) EndIf EndSwitch EndIf EndFunc ;==>_CPActionHandler Func _CPUploadFiles() Return(FileOpenDialog("Select File", @ScriptDir, "All (*.*)")) EndFunc ;==>_CPUploadFiles
kaisies Posted July 2, 2016 Posted July 2, 2016 Most strings evaluate to 0, which is why this is behaving unexpectedly. See note at bottom. You could use <> "" instead... I think. Not in front of a compiler at the moment https://www.autoitscript.com/autoit3/docs/intro/lang_operators.htm
orbs Posted July 2, 2016 Posted July 2, 2016 (edited) when you check if a string is not empty, compare it against an empty string, not against zero: replace this line: If $_sAHLocalFile = 0 Then with this: If $_sAHLocalFile = '' Then Edited July 2, 2016 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
Inpho Posted July 2, 2016 Author Posted July 2, 2016 (edited) Many thanks guys, I can't believe I haven't run into this problem before. It now reminds me of an example script I saw some time ago where a function would return * instead of 0. Makes sense, I'm checking for an integer when the return is a string. I figured returning 0 from a failed function would be fine, but I se the potential problems now. Looks like it's time for me to look into SetError. Func _CPActionHandler($_iAHArrayRow, $_iAHArrayCol) Local $_sAHLocalFile, $_sAHRemoteFile If $_iAHArrayCol = 0 Then Switch $_iAHArrayRow Case 1 $_sAHLocalFile = _CPUploadFiles() MsgBox(0, "", $_sAHLocalFile) ClipPut($_sAHLocalFile) If $_sAHLocalFile = "*" Then MsgBox(0, "", $_sAHLocalFile) Return (0) Else $_sAHRemoteFile = $_sAHLocalFile MsgBox(0, $_sAHLocalFile, $_sAHRemoteFile) ProgressOn("Upload Progress", $_sAHLocalFile) _FTP_ProgressUpload ( $hFTPConnectSession, $_sAHLocalFile, "/" & $_sAHRemoteFile, _UpdateProgress) ProgressOff() ;_FTP_ProgressUpload ( $hFTPConnectSession, $_sAHFile, "/Scripts/test2/" & $_sAHFile, _UpdateProgress) $aa = @error MsgBox(0, "", $aa) EndIf EndSwitch EndIf EndFunc ;==>_CPActionHandler Func _CPUploadFiles() $_sUFFile = FileOpenDialog("Select File", @ScriptDir, "All (*.*)") If @error Then Return("*") Return($_sUFFile) EndFunc ;==>_CPUploadFiles Edited July 2, 2016 by Inpho
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