Jump to content

Hassle with Adlibs!


Recommended Posts

Hey there, needing some help with adlibs, its working fine except from one problem

What I have is my main function which is in a loop

F_1()

While 1

..Do stuff

Wend

Endfunc

Now at any time while that script is executing the window it deals with could close. Now if that happens then the adlib that I have will reopen the window and return to wherever it is in the F_1 function I guess? Now the problem is that if that happenes then the window will be completely different upon reloading and as such it just sits there doing nothing.

Is there anyway to get the adlib to not return to the Function as in the state it was after running and instead just restart the F_1 function?

Thanks in advance,

marscom

Link to comment
Share on other sites

I'm not at all clear what the construction of your script is.

Is F_1() the function being called by ADLibEnable? Is the while loop part of the F_1() function?

I think that in your AdLib function you must detect is the window you are dealing exists or not. So in the adlibe function set a global variable to indicate that you have had to restart it. Then in your loop test the variable to see if you should start again.

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

I'm not at all clear what the construction of your script is.

Is F_1() the function being called by ADLibEnable? Is the while loop part of the F_1() function?

I think that in your AdLib function you must detect is the window you are dealing exists or not. So in the adlibe function set a global variable to indicate that you have had to restart it. Then in your loop test the variable to see if you should start again.

Sorry my mistake.

F_1() is the main loop, it has a while 1 loop in it and is called initially on the script starting.

The adlib function is another function completely. I need it to check if the window exist and if not, to reopen it and then start the F_1() loop from the beginning again.

Note that f_1() is quite long so I could not have a error flag in the adlib and also have an error check before any function in the F_1 loop because there is a ridiculous amount of code needed to do this.

Is there any way to terminate the loop after the adlib function has detected that there is no window and resolved the problem and then to start executing the loop again?

Link to comment
Share on other sites

Note that f_1() is quite long so I could not have a error flag in the adlib and also have an error check before any function in the F_1 loop because there is a ridiculous amount of code needed to do this.

Is there any way to terminate the loop after the adlib function has detected that there is no window and resolved the problem and then to start executing the loop again?

You may need to use a Global variable common to both functions to conditionally flag of error and use ContinueLoop within your loop to restart the loop cycle. The amount of code means little to what you may need to do.

:D

Link to comment
Share on other sites

You may need to use a Global variable common to both functions to conditionally flag of error and use ContinueLoop within your loop to restart the loop cycle. The amount of code means little to what you may need to do.

:D

Sorry I dont quite get what you mean? Is this adding if statements in the loop to check for errors before continueing?

Link to comment
Share on other sites

Yes, using If statements or what ever it takes to check. At safe times to check and restart the loop.

Here is an example to show how a variable can be used as a condition to flag an event.

Global $error ; variable to flag error condition

Opt('GUIOnEventMode', True)
$hGui = GUICreate('Test', 250, 100)
$label = GUICtrlCreateLabel('', 20, 20, 150, 20)
GUICtrlCreateButton('Exit', 20, 50, 80)
GUICtrlSetOnEvent(Default, '_Exit')
GUICtrlCreateButton('Error Condition', 120, 50, 100)
GUICtrlSetOnEvent(Default, '_Error')
GUISetState()

WinSetOnTop($hGui, '', True)
Run('Notepad')
AdlibEnable('_Adlib')

_Loop()

Exit

Func _Loop()
    While 1
        Sleep(250)
        If _CheckError() Then ContinueLoop
    WEnd
EndFunc

Func _Adlib()
    If Not WinExists('Untitled') Then
        $error = 1
        Run('Notepad')
        GUICtrlSetData($label, '$error = 1')
        Sleep(1000)
        GUICtrlSetData($label, '')
    EndIf
EndFunc

Func _CheckError()
    If $error Then
        $error = 0
        GUICtrlSetData($label, 'ContinueLoop')
        Sleep(1000)
        GUICtrlSetData($label, '')
    EndIf
EndFunc

Func _Error()
    WinKill('Untitled')
EndFunc

Func _Exit()
    AdlibDisable()
    WinKill('Untitled')
    Exit
EndFunc

You may add error checking within your loop how ever you want and as needed. This is just an example and you may think of better arrangement or ideas to make the UDFs suit your needs.

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