Jump to content

File Deletion


 Share

Go to solution Solved by kylomas,

Recommended Posts

Here is my code I am using to delete certain files. It works, BUT not quite like I thought it would.

Here is what happens"

When the MsgBox is answered YES, the file is suppose to get deleted and it does but it does so AFTER I exit the application.  I know this because after answering YES, I opened my file explorer and checked the path/file.  It was still there.  I exited the application and again checked my file explorer and the file being deleted was gone.

So any ideas on how to make it immediately delete would be appreciated.

Thanks

Hobbyist

case $idDelete
    GUICtrlSetState($idDelete, $GUI_CHECKED)
    if FileExists ( "c:\Monthly Log\" &  _MyMonth($sMon) & ".csv" ) and _
    MsgBox($MB_YESNO, "Delete", " Delete This Month ? : "& _MyMonth($sMon) ) = 6 Then
    FileDelete("c:\Monthly Log\" &  _MyMonth($sMon) & ".csv")

    elseif  FileExists ( "c:\Monthly Log\" &  _MyMonth($sMon) & ".csv" ) < 1 Then
    MsgBox($MB_SYSTEMMODAL, "Check", "File Does Not Exist.")
    EndIf
Link to comment
Share on other sites

Hobbyist,

This deletes the file on Win 7 Autoit 3.3.12...

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <array.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('')
local $aSize    =   wingetclientsize($gui010)
local $iddelete =   guictrlcreatebutton('Delete',20,20,$aSize[0]-40,$aSize[1]-40)
                    guisetstate()

local $sMon = 'October'
while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $idDelete
            GUICtrlSetState($idDelete, $GUI_CHECKED)
            if FileExists ( "c:\Monthly Log\" &  _MyMonth($sMon) & ".csv" ) and _
            MsgBox($MB_YESNO, "Delete", " Delete This Month ? : "& _MyMonth($sMon) ) = 6 Then
            FileDelete("c:\Monthly Log\" &  _MyMonth($sMon) & ".csv")

            elseif  FileExists ( "c:\Monthly Log\" &  _MyMonth($sMon) & ".csv" ) < 1 Then
            MsgBox($MB_SYSTEMMODAL, "Check", "File Does Not Exist.")
            EndIf
    EndSwitch
WEnd

func _MyMonth($sMon)
    return 'October'
endfunc

Note - The case routine is exactly as you posted it.  I added code to get it to run.  Your problem lies elswhere.  Do as John One advised and post a runnable reproducer, please.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Thank you!

I needed to know if its my code for that section or elsewhere and you answered that.  I'm new at this so, I'm always looking for comments from the more advanced folks. Knowing my case routine is valid was helpful.

I will give it a shot looking elsewhere first and if frustration builds I will return with the code. 

Link to comment
Share on other sites

Trouble shooting this stuff is as challenging as is writing script, if you are new to it.  I'm starting right after dinner.

So as I start here is my question set:

Would an advance coder start by checking where the variables in the section above are used else where? Narrow it down to some method of checking?? 

Right out of the shoot I have this question - If I have used FileOpen with one of the variables elsewhere in the code BUT did NOT use FileClose - could that be my problem?  I seem to recall it being an option rather than a requirement.

Link to comment
Share on other sites

I'm back.

Here is what I did, working backwards.  I deleted out any code not associated with the current issue at hand - found a few issues.

So here is what I am doing.

Radio button selects month

Click Spending/Budget button and follow msgbox. Creates month file named based upon Radio button selected.

You can use the menu bar as well.

After creating a "month" file, use menu bar "File" to delete the file. It will delete like I want it to.

It all works UNTIL this. Create a "month" file, but before deleting it click the same Spending?Budget button again (as if you accidently clicked it again) and then try the delete action.  It will NOT delete under this scenario but I don't know why.

I am allowing a file to be created but its empty as can be seen in the msgbox as well.

So bottom line - clicking the Spending?Budget button more than ONCE or using the menu bar action more than ONCE prevents the file from being deleted. Use it once and everything is fine.

Hope I made this somewhat clear. 

Thanks for any trouble shooting help.

Hobbyist

;<<<<<<<<<<<<<<<<<<<<<<<<
#include <Array.au3> ;for American Express function
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
;#include <StaticConstants.au3>
#include <String.au3> ; Only used to fill array
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
 #include <GuiButton.au3>
;<<<<<<<<<<<<

#Region ### START Koda GUI section ### Form=C:\Users\\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Dash Board", 680, 515, 150, 100) ;height was 480

$List1 = GUICtrlCreateListview("", 192, 72, 470, 260,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)

GUICtrlSetState($List1,$GUI_enABLE)

$List3 = GUICtrlCreateListview("", 192, 72, 470, 260,$LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List3, $COLOR_aqua)

GUICtrlSetState($List3,$GUI_DISABLE);
GUICtrlSetState($List3,$GUI_HIDE)

$Button14 = GUICtrlCreateButton("Spending vs Budget", 10, 140, 158, 33)
GUICtrlSetState($Button14,$GUI_enABLE)
GUICtrlSetState($Button14,$GUI_FOCUS)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$Button15 = GUICtrlCreateButton("Spending Log", 10, 180, 158, 33)
GUICtrlSetState($Button15,$GUI_enABLE)
GUICtrlSetState($Button15,$GUI_FOCUS)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$Group1 = GUICtrlCreateGroup("Default Month", 28, 230, 121, 121)

GUICtrlCreateGroup("", -99, -99, 1, 1)

Local $idFilemenu = GUICtrlCreateMenu("&File") ;added August 3,2014
Local $idDelete = GUICtrlCreateMenuItem("Delete Spending Log", $idFilemenu) ;added Oct 18, 2014
Local $idRunmenu = GUICtrlCreateMenu("&Run") ;added August 3,2014
Local $idSpendingLog = GUICtrlCreateMenuItem("Spending Log", $idRunmenu)
GUICtrlSetState($idSpendingLog, $GUI_CHECKED) ;defaults to BudgetLog at startup
local $idFileitem2 = GUICtrlCreateMenuItem("Spending vs Budget", $idRunmenu)

GUISetState(@SW_SHOW)
;#EndRegion ### END Koda GUI section ###

Global $sIni = @LocalAppDataDir & "\AE Dash Board Settings.ini"

Global $Monthmgr ;my change Oct 6
global $sMon ;my change Oct 6
Global $aRadio[13]
Global $aMon[13] = ["", "January", "February", "March", "April", "May", "June", _
                    "July", "August", "September", "October", "November", "December"]
$cEnterPressed = GUICtrlCreateDummy();x

global $listswitch = 1 ;switch between List 1 & 2 ;x

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]];x
GUISetAccelerators($aAccelKeys);x

global $budgetlogfile
global $ABC

For $i = 1 To 12
    $iX = (($i > 6) ? (103) : (38))
    $iY = 242 + (17 * Mod($i - 1, 6))
    $aRadio[$i] = GUICtrlCreateRadio(StringLeft($aMon[$i], 3), $iX, $iY, 45, 17)
Next

GUICtrlSetState($aRadio[_MyCheck()], $GUI_CHECKED)

GUISetState()

While 1

   $iMsg = GUIGetMsg()
         Switch $iMsg
             Case $GUI_EVENT_CLOSE
                 Exit
            Case $aRadio[1] To $aRadio[12]

                For $i = 1 To 12
                    GUICtrlSetState($aRadio[$i], $GUI_FOCUS)
                    If $iMsg = $aRadio[$i] Then
                        $Monthmgr = $aMon[$i] &" " &StringTrimRight(_NowCalc() ,15)
                        _MyChoice($Monthmgr)
                        _MyValue($i)

                        ExitLoop
                    EndIf
                Next

        Case $Button14;Spending vs Budget

                  _MyExp ()
                    if FileGetSize ("c:\2014 Budget\Monthly Log\" & $ABC & ".csv")< 1 Then
                        MsgBox($MB_SYSTEMMODAL, "Error", " No Entries For : "&$ABC )

                            EndIf

        Case $idDelete  ; delete file from menu bar
                if GUICtrlSetState($idDelete, $GUI_CHECKED) then
                if FileExists ( "c:\2014 Budget\Monthly Log\" &  _MyMonth($sMon) & ".csv" ) and _
                        MsgBox($MB_YESNO, "Delete", " Delete This Month ? : "& _MyMonth($sMon) ) = 6 Then
                                FileDelete("c:\2014 Budget\Monthly Log\" &  _MyMonth($sMon) & ".csv")

                    elseif  FileExists ( "c:\2014 Budget\Monthly Log\" &  _MyMonth($sMon) & ".csv" ) < 1 Then
                                MsgBox($MB_SYSTEMMODAL, "Check", "File Does Not Exist.")
                            EndIf
                            Fileclose ( "c:\2014 Budget\Monthly Log\" &  _MyMonth($sMon) & ".csv" )
EndIf
                        GUICtrlSetState($idDelete, $GUI_unCHECKED)


        Case $idFileitem2 ;spending vs budget
            _GUICtrlListView_DeleteAllItems ( $List3 ) ;added 10/09/2014
            GUICtrlSetState($idFileitem2, $GUI_CHECKED)
            GUICtrlSetState($idSpendingLog, $GUI_unCHECKED)

            GUICtrlSetState($List1,$GUI_DISABLE);
            GUICtrlSetState($List1,$GUI_HIDE)


            GUICtrlSetState($List3,$GUI_enABLE);
            GUICtrlSetState($List3,$GUI_show)


            $listswitch = 3
            If _GUICtrlListView_GetItemCount ( $List3 ) = 0 Then
             _MyExp ()
            EndIf
                if FileGetSize ("c:\2014 Budget\Monthly Log\" & $ABC & ".csv")< 1 Then
                        MsgBox($MB_SYSTEMMODAL, "Error", " No Entries For : "&$ABC )

                            EndIf

            Case $Button15 ;Expense Log

                GUICtrlSetState($idFileitem2, $GUI_unCHECKED)
                GUICtrlSetState($idSpendingLog, $GUI_CHECKED)
                GUICtrlSetState($List1,$GUI_enABLE);
                GUICtrlSetState($List1,$GUI_show)


                GUICtrlSetState($List3,$GUI_DISABLE);
                GUICtrlSetState($List3,$GUI_HIDE)


                $ListDel = string($List1)
                $ListSave =string($List1)

            Case $idSpendingLog ;Expense Log from menu bar


                GUICtrlSetState($idFileitem2, $GUI_unCHECKED)
                GUICtrlSetState($idSpendingLog, $GUI_CHECKED)
                GUICtrlSetState($List1,$GUI_enABLE);
                GUICtrlSetState($List1,$GUI_show)


                GUICtrlSetState($List3,$GUI_DISABLE);
                GUICtrlSetState($List3,$GUI_HIDE)

                    $listswitch = 1
                     $filemode = 1
                $ListDel = string($List1)
                $ListSave =string($List1)

    EndSwitch

WEnd
_GUICtrlListView_UnRegisterSortCallBack($List3)


Func _MyChoice($sMon) ;Month Name Chosen -write -$Monthmgr
    IniWrite($sIni, "Month", "Month", $sMon)
EndFunc   ;==>_MyChoice

Func _MyValue($i) ;Month Checked For MyChoice - write value of $i
    IniWrite($sIni, "Checked", "Checked", $i)
EndFunc   ;==>_MyValue

Func _MyCheck() ;Month Checked For MyChoice - read at next startup its MyValue
    Return IniRead($sIni, "Checked", "Checked", 1) ; Default is 1
EndFunc   ;==>_MyCheck

Func _MyMonth($sMon) ;Month Name Chosen -read -$Monthmgr
    Return IniRead($sIni, "Month", "Month", "January") ; Default is 1
EndFunc   ;==>_MyMonth

Func today() ;Return the current date in mm/dd/yyyy form
    Return (@MON & "-" & @MDAY & "-" & @YEAR)
EndFunc   ;==>today


Func _MyExp ()
$ABC =  _MyMonth($sMon)
Local $budgetlogfile = FileOpen ("c:\2014 Budget\Monthly Log\" & $ABC & ".csv", 0)
if FileGetSize ("c:\2014 Budget\Monthly Log\" & $ABC & ".csv")< 1 Then
                        MsgBox($MB_SYSTEMMODAL, "Error", " No Entries For : "&$ABC )

                            EndIf

   If $budgetlogfile = -1 Then
            if MsgBox($MB_YESNO,  "Error", "Month Does Not Exist." &@crlf &   "Create Month: "&$ABC ) = 6 Then
                     $File =   "c:\2014 Budget\Monthly Log\" & $ABC & ".csv"
                        _FileCreate ( $File )


                    Return True
                EndIf

                        EndIf

EndFunc
Link to comment
Share on other sites

Hobbyist,

As near as I can tell the problem is that you have the file open when you try to delete it.

In the case for $idDelete you have

FileClose("c:\2014 Budget\Monthly Log\" & _MyMonth($sMon) & 
".csv")

FileClose take a file handle.  It is also placed incorrectly, should be before the FileDelete in the same routine.

In the function _MyExp() you open the file with

Local $budgetlogfile = FileOpen("c:\2014 Budget\Monthly Log\" & $ABC & 
".csv", 0)

but you do not close the handle, nor do you use the handle for anything.

Net effect is that the file is still open when the FileDelete is attempted in the MSG loop.

kylomas

edit: clarification

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Hobbyist,

If I understand what you are trying to do I would code the $idDelete case something like this...

If GUICtrlSetState($idDelete, $GUI_CHECKED) Then
                If FileExists("c:\2014 Budget\Monthly Log\" & _MyMonth($sMon) & ".csv") then
                    if MsgBox($MB_YESNO, "Delete", " Delete This Month ? : " & _MyMonth($sMon)) = 6 Then
                        FileClose($budgetlogfile)
                        $ret = FileDelete("c:\2014 Budget\Monthly Log\" & _MyMonth($sMon) & ".csv")
                        ConsoleWrite($ret = 1 ? 'File deleted' & @CRLF : 'File delete failed' & @crlf)
                    endif
                Else
                    MsgBox($MB_SYSTEMMODAL, "Check", "File Does Not Exist.")
                endif
                GUICtrlSetState($idDelete, $GUI_unCHECKED)
            endif

kylomas

edit: code copied incorrectly

edit2: Some errors corrected but the deletion after multiple file open problem remains

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • Solution

Hobbyist,

FileClose was in the wrong place (should have been in function _MyExp().  The following is the complete code and works for multiple opens.

;<<<<<<<<<<<<<<<<<<<<<<<<
#include <Array.au3> ;for American Express function
#include <ButtonConstants.au3>
#include <ColorConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
;#include <StaticConstants.au3>
#include <String.au3> ; Only used to fill array
#include <WindowsConstants.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <GuiButton.au3>
;<<<<<<<<<<<<

#Region ### START Koda GUI section ### Form=C:\Users\\Autoit Trys\Vendors Trials\My combo Form Test.kxf
$main = GUICreate("Dash Board", 680, 515, 150, 100) ;height was 480

$List1 = GUICtrlCreateListView("", 192, 72, 470, 260, $LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List1, $COLOR_aqua)

GUICtrlSetState($List1, $GUI_enABLE)

$List3 = GUICtrlCreateListView("", 192, 72, 470, 260, $LVS_SINGLESEL, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT)
GUICtrlSetBkColor($List3, $COLOR_aqua)

GUICtrlSetState($List3, $GUI_DISABLE);
GUICtrlSetState($List3, $GUI_HIDE)

$Button14 = GUICtrlCreateButton("Spending vs Budget", 10, 140, 158, 33)
GUICtrlSetState($Button14, $GUI_enABLE)
GUICtrlSetState($Button14, $GUI_FOCUS)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$Button15 = GUICtrlCreateButton("Spending Log", 10, 180, 158, 33)
GUICtrlSetState($Button15, $GUI_enABLE)
GUICtrlSetState($Button15, $GUI_FOCUS)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")

$Group1 = GUICtrlCreateGroup("Default Month", 28, 230, 121, 121)

GUICtrlCreateGroup("", -99, -99, 1, 1)

Local $idFilemenu = GUICtrlCreateMenu("&File") ;added August 3,2014
Local $idDelete = GUICtrlCreateMenuItem("Delete Spending Log", $idFilemenu) ;added Oct 18, 2014
Local $idRunmenu = GUICtrlCreateMenu("&Run") ;added August 3,2014
Local $idSpendingLog = GUICtrlCreateMenuItem("Spending Log", $idRunmenu)
GUICtrlSetState($idSpendingLog, $GUI_CHECKED) ;defaults to BudgetLog at startup
Local $idFileitem2 = GUICtrlCreateMenuItem("Spending vs Budget", $idRunmenu)

GUISetState(@SW_SHOW)
;#EndRegion ### END Koda GUI section ###

Global $sIni = @LocalAppDataDir & "\AE Dash Board Settings.ini"

Global $Monthmgr ;my change Oct 6
Global $sMon ;my change Oct 6
Global $aRadio[13]
Global $aMon[13] = ["", "January", "February", "March", "April", "May", "June", _
        "July", "August", "September", "October", "November", "December"]
$cEnterPressed = GUICtrlCreateDummy();x

Global $listswitch = 1 ;switch between List 1 & 2 ;x

Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]];x
GUISetAccelerators($aAccelKeys);x

Global $budgetlogfile
Global $ABC

For $i = 1 To 12
    $iX = (($i > 6) ? (103) : (38))
    $iY = 242 + (17 * Mod($i - 1, 6))
    $aRadio[$i] = GUICtrlCreateRadio(StringLeft($aMon[$i], 3), $iX, $iY, 45, 17)
Next

GUICtrlSetState($aRadio[_MyCheck()], $GUI_CHECKED)

GUISetState()

local $ret  ; <-- use for function results checking

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $aRadio[1] To $aRadio[12]

            For $i = 1 To 12
                GUICtrlSetState($aRadio[$i], $GUI_FOCUS)
                If $iMsg = $aRadio[$i] Then
                    $Monthmgr = $aMon[$i] & " " & StringTrimRight(_NowCalc(), 15)
                    _MyChoice($Monthmgr)
                    _MyValue($i)

                    ExitLoop
                EndIf
            Next

        Case $Button14;Spending vs Budget

            _MyExp()
            If FileGetSize("c:\2014 Budget\Monthly Log\" & $ABC & ".csv") < 1 Then
                MsgBox($MB_SYSTEMMODAL, "Error", " No Entries For : " & $ABC)

            EndIf

        Case $idDelete ; delete file from menu bar
            If GUICtrlSetState($idDelete, $GUI_CHECKED) Then
                If FileExists("c:\2014 Budget\Monthly Log\" & _MyMonth($sMon) & ".csv") then
                    if MsgBox($MB_YESNO, "Delete", " Delete This Month ? : " & _MyMonth($sMon)) = 6 Then
                        $ret = FileDelete("c:\2014 Budget\Monthly Log\" & _MyMonth($sMon) & ".csv")
                        ConsoleWrite($ret = 1 ? 'File deleted' & @CRLF : 'File delete failed' & @crlf)
                    endif
                Else
                    MsgBox($MB_SYSTEMMODAL, "Check", "File Does Not Exist.")
                endif
                GUICtrlSetState($idDelete, $GUI_unCHECKED)
            endif

        Case $idFileitem2 ;spending vs budget
            _GUICtrlListView_DeleteAllItems($List3) ;added 10/09/2014
            GUICtrlSetState($idFileitem2, $GUI_CHECKED)
            GUICtrlSetState($idSpendingLog, $GUI_unCHECKED)

            GUICtrlSetState($List1, $GUI_DISABLE);
            GUICtrlSetState($List1, $GUI_HIDE)


            GUICtrlSetState($List3, $GUI_enABLE);
            GUICtrlSetState($List3, $GUI_show)


            $listswitch = 3
            If _GUICtrlListView_GetItemCount($List3) = 0 Then
                _MyExp()
            EndIf
            If FileGetSize("c:\2014 Budget\Monthly Log\" & $ABC & ".csv") < 1 Then
                MsgBox($MB_SYSTEMMODAL, "Error", " No Entries For : " & $ABC)

            EndIf

        Case $Button15 ;Expense Log

            GUICtrlSetState($idFileitem2, $GUI_unCHECKED)
            GUICtrlSetState($idSpendingLog, $GUI_CHECKED)
            GUICtrlSetState($List1, $GUI_enABLE);
            GUICtrlSetState($List1, $GUI_show)


            GUICtrlSetState($List3, $GUI_DISABLE);
            GUICtrlSetState($List3, $GUI_HIDE)


            $ListDel = String($List1)
            $ListSave = String($List1)

        Case $idSpendingLog ;Expense Log from menu bar


            GUICtrlSetState($idFileitem2, $GUI_unCHECKED)
            GUICtrlSetState($idSpendingLog, $GUI_CHECKED)
            GUICtrlSetState($List1, $GUI_enABLE);
            GUICtrlSetState($List1, $GUI_show)


            GUICtrlSetState($List3, $GUI_DISABLE);
            GUICtrlSetState($List3, $GUI_HIDE)

            $listswitch = 1
            $filemode = 1
            $ListDel = String($List1)
            $ListSave = String($List1)

    EndSwitch

WEnd
_GUICtrlListView_UnRegisterSortCallBack($List3)


Func _MyChoice($sMon) ;Month Name Chosen -write -$Monthmgr
    IniWrite($sIni, "Month", "Month", $sMon)
EndFunc   ;==>_MyChoice

Func _MyValue($i) ;Month Checked For MyChoice - write value of $i
    IniWrite($sIni, "Checked", "Checked", $i)
EndFunc   ;==>_MyValue

Func _MyCheck() ;Month Checked For MyChoice - read at next startup its MyValue
    Return IniRead($sIni, "Checked", "Checked", 1) ; Default is 1
EndFunc   ;==>_MyCheck

Func _MyMonth($sMon) ;Month Name Chosen -read -$Monthmgr
    Return IniRead($sIni, "Month", "Month", "January") ; Default is 1
EndFunc   ;==>_MyMonth

Func today() ;Return the current date in mm/dd/yyyy form
    Return (@MON & "-" & @MDAY & "-" & @YEAR)
EndFunc   ;==>today


Func _MyExp()
    $ABC = _MyMonth($sMon)
    Local $budgetlogfile = FileOpen("c:\2014 Budget\Monthly Log\" & $ABC & ".csv", 0)
    If FileGetSize("c:\2014 Budget\Monthly Log\" & $ABC & ".csv") < 1 Then
        MsgBox($MB_SYSTEMMODAL, "Error", " No Entries For : " & $ABC)

    EndIf

    If $budgetlogfile = -1 Then
        If MsgBox($MB_YESNO, "Error", "Month Does Not Exist." & @CRLF & "Create Month: " & $ABC) = 6 Then
            $File = "c:\2014 Budget\Monthly Log\" & $ABC & ".csv"
            _FileCreate($File)
            Return True
        EndIf
    EndIf
    fileclose($budgetlogfile)

EndFunc   ;==>_MyExp

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

kylomas

Thanks for being patient with me and thanks for the corrective measures.

As I understand it, sequentially misplaced commands were the root cause of my malfunctioning results. It was not obvious to me that fileopen and fileclose had to both remain in the same function.  I just kept spinning my wheels with the results.

It was yet another good learning experience for me.

Hobbyist

Link to comment
Share on other sites

Hi Hobbyist,

FileOpen and FileClose do NOT have to be in the same function.  In this case, you created a file handle ($budgetlogfile) that is local to the function _MyExp() therefore the handle could only be used within that function. 

Two things to take away from this:

  1. Use error checking, either a return from the function or @ERROR
  2. Understand when to use a file handle and when to use a file name (spelled out in the Help file) 

You show a nice grasp of the language for a new user, previous coding experience?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

  • 2 weeks later...

kylomas

Nice take aways for me to focus on. Thanks.

No, no coding experience. In fact I accidently stumbled upon Autoit while surfing the web one time.

So then I have spent time attempting to learn it, follow the lead of those experienced folks and learn from mistakes.  For the most part I always attempt to solve any issue my self and turn to the forum when my frustration levels hit high.  I would rather not be a "cut and paste" coder.

Thanks again and have a great balance of the year.

Hobbyist.

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