Jump to content

UDF executed on exe start


Recommended Posts

As the title suggests, I have aa UDF which terminates the program. Unfortunately the script reads the function where I defined it and instantly executes it, closing my program. Apparently I don't have the proper syntax for defining functions. I've used searches on this forum and the help file to mimic the syntax, which looks really basic, and yet I must have it wrong. Where in a script should the defining of functions be placed? Is the syntax:

Func FunctionName()

;What you want to do such as:

Exit

EndFunc

? This seems so unnecessarily difficult, and therefor am questioning my sanity.

Edited by funcwtf
Link to comment
Share on other sites

As the title suggests, I have aa UDF which terminates the program. Unfortunately the script reads the function where I defined it and instantly executes it, closing my program. Apparently I don't have the proper syntax for defining functions. I've used searches on this forum and the help file to mimic the syntax, which looks really basic, and yet I must have it wrong. Where in a script should the defining of functions be placed? Is the syntax:

Func FunctionName()

;What you want to do such as:

Exit

EndFunc

? This seems so unnecessarily difficult, and therefor am questioning my sanity.

If you want to end a function before the end of the code in the fiunction use return, but exit means exit the whole script.

If exit is at the end of the code in your function then just delete the exit line.

Edit:On the other hand I'm not sure I understood your problem. Is the exit statement meant to exit the whole script? If it is then can you explain your problem in another way?

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

As the title suggests, I have aa UDF which terminates the program. Unfortunately the script reads the function where I defined it and instantly executes it, closing my program. Apparently I don't have the proper syntax for defining functions. I've used searches on this forum and the help file to mimic the syntax, which looks really basic, and yet I must have it wrong. Where in a script should the defining of functions be placed? Is the syntax:

Func FunctionName()

;What you want to do such as:

Exit

EndFunc

? This seems so unnecessarily difficult, and therefor am questioning my sanity.

if you are asking where to drop this function, put it in the area that you definded all your other functions - normally the bottom section of the script and then you would call it from some other location - if not I am not sure what you are asking

if msgbox(4, "Answer", "Yes or No") = 6 then
; calling the function
 functionname()
else
exit
endif

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;FUNCTIONS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func FunctionName()
     ;What you want to do such as:
     Exit
EndFunc

Not tested code

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

I just found out where the problem is, I just don't understand why...

;Early in the script, where I think the problem is:
$Cancel = GuiCtrlCreateButton("&Cancel",320,275,100,30)
         ;Guictrlsetonevent(-1, _terminate())

;End of the script:
Func _terminate()
    Exit
EndFunc

-When I run my script the script instantly closes, could someone please explain this to me?

Link to comment
Share on other sites

Alright, I think my understanding to how the script was running, and should run was a bit wrong, and therefore was giving you all some confusing information, therefore I'll back up further and give the broad view of what's going on. I've got a GUI that everything works perfectly on, two buttons, Submit and Cancel. When the Submit button is clicked, a bunch of code is executed through a do/while statement. While the script is running in the background doing all that it needs to do, just the way I want it to, the Cancel button then becomes inoperable. The loop will run for aprox 2 hrs on it's own before finishing if left alone, but the user needs to have the option to cancel whenever desired, so... could someone give me guidance as to how to keep the Cancel button operational while a do/while loop statement is being run?

Sorry for the confusing explanations above, as I thought the problem was much smaller so to speak.

Link to comment
Share on other sites

Sounds like you might need GUIOnEventMode... although I wonder if that would work. Give it a shot at least.

Otherwise you might be able to use AdlibEnable to poll for the user requesting something to be stopped (I know a Cancel "checkbox" would work, but perhaps not a button).

check the helpfile on those two, but you may have better success with AdlibEnable, i'm just not sure on GUIOnEventMode

edit: looks like GUISetOnEvent should work for you, but you'll have to change up how your gui works.

edit2: you could also have your loop checking for a variable that gets set on a hotkey (see hotkeyset)... just another idea.

Edited by fisofo
Link to comment
Share on other sites

sorry for the late reply and thanks for the advice. I've been trying what you suggested and, either A) It doesn't work or :P It works, I'm just not seeing how, hah. I'll keep fooling around, until i become too sleep deprived to continue.

Link to comment
Share on other sites

Ooh ooh I know I know!

When you use the OnEvent functions, you actually have to pass the name of the function as a string.

Because when you do this:

Guictrlsetonevent(-1, _terminate())oÝ÷ ØZrÛ«º{-ë^®h§j׺w-ð'!{­³*.®Ç+m¢­Ýý²·­º¹ïj[jwméà÷­«m¢Ø^:q/z{_ºw-Ö«r¢éÞyÛhv¬²)©&®¶­sdwV7G&Ç6WFöæWfVçBÓÂgV÷Cµ÷FW&ÖæFRgV÷C²

Tadaa. :P

Hope that works.

*Edit: Clarification

Edited by Saunders
Link to comment
Share on other sites

You were definitely right about sending the function as a string, unfortunately it didn't fix my initial problem. I then tried the adlib command, remembering to send the function as a string as well, but this also did not work... and I think it may be due to the function i have adlib direct to... which is:

Func TerminateCheck();Side note for those following this thread, i changed the name of the function, just to be more descriptive..
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $Cancel Then
       Exit
    EndIf
EndFunc

I'm guessing this must not be right, or it's right, but $msg either isn't being updated, or there are no events being passed to GUIGetMsg() for $msg to even receive. Any ideas... this is driving me a bit crazy...

Edit: 4:00 am here... I'm going to pick this up in the morning...

On a side note, it doesn't make sense to me why GUICtrlsetonevent(-1, "_terminate") didn't work...

**Edit: hahaha, I just tried it again with the GUICtrlSetOnEvent command out of curiosity... and what do you know it worked. There was just like a 3 second delay between the time i clicked Cancel and it actually closing.. so i kept closing it manually before it'd register.... d'OH, thanks Sauders, I can peacefully go to bed now :P

Edited by funcwtf
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...