Jump to content

cant find what is wrong


Recommended Posts

Hi All

Please caould someone have a look through the following (i know its really messy im just learning) and let me know if you can see what is wrong.

The problem I am having is using the delete button. This works fine if you click it the first time it is opened however if you use the new button first you cant delete.

The program is yet another sendto FTP app. I just needed a project to get me started learning and it seemed like something I could do.

To see it working you need to compile it and stick it in your send to folder with the ini (renamed as txt to allow upload)

; Script Start - Add your code below here
#include <GUIConstants.au3>
#include <GuiList.au3>
;get the variable data passed
$total_files = $CmdLine[0]
$sendtoINI=@UserProfileDir & "\SendTo\SendtoFTP.ini"
;build the gui

$Form1 = GUICreate("FTP --->", 153, 167, 193, 115)
$List1 = GUICtrlCreateList("", 8, 8, 137, 110)
$Button1 = GUICtrlCreateButton("send", 8, 128, 65, 25, 0)
$Button2 = GUICtrlCreateButton("new", 79, 120, 65, 20, 0)
$Button3 = GUICtrlCreateButton("delete", 79, 140, 65, 20, 0)

;read from the ini file to find the locations
$var = IniReadSectionNames($sendtoINI)
;write these to the list view
For $i = 1 To $var[0]
    _GUICtrlListAddItem($List1, $var[$i])
Next

;show the GUI
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
        ;Destroy the GUI including the controls
            GUIDelete()
        ;Exit the script
            Exit
            
        Case $nMsg = $Button1
            $ini_section = _GUICtrlListGetText($List1, _GUICtrlListSelectedIndex($List1))
            Call("transfer")
            
        Case $nMsg = $Button2
            Call("add_location")
            
            
        Case $nMsg = $Button3
            $ini_section = _GUICtrlListGetText($List1, _GUICtrlListSelectedIndex($List1))
            Call("delete_location")
            
            
    EndSelect
WEnd

Func transfer()
    
    $var = IniReadSection($sendtoINI, $ini_section)

    For $i = 1 To $total_files
        $file = FileOpen("C:\ftp_send.txt", 1)
    ;Write the input file for the FTP session.
        FileWrite($file, "open " & $var[1][1] & @CRLF)
        FileWrite($file, $var[2][1] & @CRLF)
        FileWrite($file, $var[3][1] & @CRLF)
        FileWrite($file, "binary" & @CRLF)
        FileWrite($file, "cd " & """" & $var[4][1] & """" & @CRLF)
        FileWrite($file, "put " & """" & $CmdLine[$i] & """" & @CRLF)
        FileWrite($file, "close" & @CRLF)
        FileWrite($file, "bye")
        FileClose($file)
        RunWait(@ComSpec & " /c " & "ftp -s:C:\ftp_send.txt", "", @SW_SHOW)
        FileDelete("C:\ftp_send.txt")
    Next
EndFunc  ;==>transfer

Func add_location()

    $Form1 = GUICreate("AForm1", 236, 237, 291, 114)
    $Input5 = GUICtrlCreateInput("", 88, 37, 121, 21)
    $Input1 = GUICtrlCreateInput("", 88, 65, 121, 21)
    $Input2 = GUICtrlCreateInput("", 88, 95, 121, 21)
    $Input3 = GUICtrlCreateInput("", 88, 125, 121, 21)
    $Input4 = GUICtrlCreateInput("", 88, 155, 121, 21)
    $Label1 = GUICtrlCreateLabel("IP", 16, 65, 14, 17)
    $Label2 = GUICtrlCreateLabel("Username", 16, 95, 68, 17)
    $Label3 = GUICtrlCreateLabel("Password", 16, 125, 66, 17)
    $Label4 = GUICtrlCreateLabel("Location", 16, 155, 69, 17)
    $Label5 = GUICtrlCreateLabel("Name", 16, 37, 64, 17)
    $Label6 = GUICtrlCreateLabel("Add a new location", 24, 16, 127, 17)
    $Button4 = GUICtrlCreateButton("Done", 144, 192, 65, 25, 0)
    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
            ;Destroy the GUI including the controls
                GUIDelete()
            ;Exit the script
                Exit
                
            Case $nMsg = $Button4
                $ip = ""
                $username = ""
                $password = ""
                $location = ""
                $name = ""
                
                $ip = GUICtrlRead($Input1)
                $username = GUICtrlRead($Input2)
                $password = GUICtrlRead($Input3)
                $location = GUICtrlRead($Input4)
                $name = GUICtrlRead($Input5)
                
                
                If $ip = "" Or $username = "" Or $password = "" Or $location = "" Or $name = "" Then
                    MsgBox(0, "error", "missing values not allowed")
                    GUIDelete()
                    Exit
                EndIf
                
                $sData = "IP=" & $ip & @LF & "Username=" & $username & @LF & "password=" & $password & @LF & "location=" & $location
                IniWriteSection($sendtoINI, $name, $sData)
                _GUICtrlListAddItem($List1, $name)
                GUIDelete()
        EndSelect
    WEnd

EndFunc  ;==>add_location

Func delete_location()
    IniDelete($sendtoINI, $ini_section)
    _GUICtrlListClear($List1)
;read from the ini file to find the locations
    $var = IniReadSectionNames($sendtoINI)
;write these to the list view
    For $i = 1 To $var[0]
        _GUICtrlListAddItem($List1, $var[$i])
    Next

EndFunc  ;==>delete_location
Link to comment
Share on other sites

IGNORE this please.

For anyone who is interested I was stuck in loop I had destroyed teh GUI but not left the while loop.

I changed the code under add location to look like this

Func add_location()

    $Form1 = GUICreate("AForm1", 236, 237, 291, 114)
    $Input5 = GUICtrlCreateInput("", 88, 37, 121, 21)
    $Input1 = GUICtrlCreateInput("", 88, 65, 121, 21)
    $Input2 = GUICtrlCreateInput("", 88, 95, 121, 21)
    $Input3 = GUICtrlCreateInput("", 88, 125, 121, 21)
    $Input4 = GUICtrlCreateInput("", 88, 155, 121, 21)
    $Label1 = GUICtrlCreateLabel("IP", 16, 65, 14, 17)
    $Label2 = GUICtrlCreateLabel("Username", 16, 95, 68, 17)
    $Label3 = GUICtrlCreateLabel("Password", 16, 125, 66, 17)
    $Label4 = GUICtrlCreateLabel("Location", 16, 155, 69, 17)
    $Label5 = GUICtrlCreateLabel("Name", 16, 37, 64, 17)
    $Label6 = GUICtrlCreateLabel("Add a new location", 24, 16, 127, 17)
    $Button4 = GUICtrlCreateButton("Done", 144, 192, 65, 25, 0)
    GUISetState(@SW_SHOW)


    While 1
        $nMsg = GUIGetMsg()
        
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
            ;Destroy the GUI including the controls
                GUIDelete()
            ;Exit the script
                Exit
                
            Case $nMsg = $Button4
                $ip = ""
                $username = ""
                $password = ""
                $location = ""
                $name = ""
                
                $ip = GUICtrlRead($Input1)
                $username = GUICtrlRead($Input2)
                $password = GUICtrlRead($Input3)
                $location = GUICtrlRead($Input4)
                $name = GUICtrlRead($Input5)
                
                
                If $ip = "" Or $username = "" Or $password = "" Or $location = "" Or $name = "" Then
                    MsgBox(0, "error", "missing values not allowed")
                    GUIDelete()
                    Exit
                EndIf
                
                $sData = "IP=" & $ip & @LF & "Username=" & $username & @LF & "password=" & $password & @LF & "location=" & $location
                IniWriteSection($sendtoINI, $name, $sData)
                _GUICtrlListClear($List1)
;read from the ini file to find the locations
    $var = IniReadSectionNames($sendtoINI)
;write these to the list view
    For $i = 1 To $var[0]
        _GUICtrlListAddItem($List1, $var[$i])
    Next
        GUIDelete()
        ExitLoop
        EndSelect
    WEnd

EndFunc  ;==>add_location
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...