Jump to content

If statement


Go to solution Solved by rsn,

Recommended Posts

I am still learning AutoIt and I have a long way to go. 

 

I am hoping for an idea now on how to do this.  I have a conditional statement that looks to see if excel is open .  If excel is open it will send a message that excel is open and not to do anything.  If excel is NOT  open it was open it will run a function that I put int he If Statement.   So I added that fucntion to the button I created and that works w\o issue.  I could very simply replicate that statement each time change the name of the function and the issue would resolved.  The problem is that is clunky and it seems like there would be an better process .      

I have a functions called Evap1 through Evap10 each one opens a very specific file.   All fuction are the same with the exception of the file name.   What is the smoothest way to pass the function to the button without created 10 different if statments? 

Function To open File - there are 10 of these. evap1 - evap10

Func evap1()

    Run('"C:\Program Files (x86)\Microsoft Office\Office16\excel.exe" "\\fileshare\Everyone\Evap1.xlsm" ')

EndFunc

Button For the  GUI - I removed a lot of the button but there are 10 evap buttons

GUISetState(@SW_SHOW, $hGUI)
        While 1
                Switch GUIGetMsg()

                ; Open hourly EVAP1
                    case $idButton_Evap1
                    ; If statement check for excel
                    checkOrOpenExcel()
                    
                    ; Open Hourly EVAP2
                    case $idButton_Evap2
                    
                ;exits application
                Case $idButton_Exit
                Terminate()


                EndSwitch
        WEnd

 

My Conditional Statment

;Function to check to see if excel is open
Func checkOrOpenExcel()

    ;looks for the process excel.exe if it is open then prompt file is alreday open
    If ProcessExists ("excel.exe") Then

        msgbox($MB_SYSTEMMODAL, "", "File is Already Open")


    else
        ;If is is not open it will open the fuction for excel
        evap1()

    EndIf

EndFunc

 

 

 

 

 

 

 

 

.   

 

 

Edited by MichaelCrawley
clerification
Link to comment
Share on other sites

  • Solution

Maybe differentiate it as part of the argument of the function?

checkOrOpenExcel("1")

Func checkOrOpenExcel($sArg)
    If ProcessExists ("excel.exe") Then
        msgbox($MB_SYSTEMMODAL, "", "File is Already Open")
    else
        if $sArg=1 then evap1()
        if $sArg=2 then evap2()
    EndIf
EndFunc

There are probably much better ways to do it since the above may trigger overflow if you have a loop going.

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