Jump to content

If statement misbehaving severely


Recommended Posts

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?

iFqbIlM.png

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

 

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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