rm4453

(SOLVED)Calling Function That Calls Original Function

13 posts in this topic

#1 ·  Posted (edited)

How would I get this code to work? If not possible/If there is a better way... How would I do it? I can't seem to get it to work properly...

 

Func Go()
;Do stuff
Re-Go()
EndFunc

Func Re-Go()
Go()
EndFunc

 

Edited by rm4453
(Solved)

Share this post


Link to post
Share on other sites



Not sure why you don't just use a loop but here you go

Go()

Func Go()
    ;DoStuff
    ReGo()
EndFunc   ;==>Go

Func ReGo()
    Go()
EndFunc   ;==>Re-Go

 

Share this post


Link to post
Share on other sites
18 minutes ago, Dgameman1 said:

Not sure why you don't just use a loop but here you go

Go()

Func Go()
    ;DoStuff
    ReGo()
EndFunc   ;==>Go

Func ReGo()
    Go()
EndFunc   ;==>Re-Go

 

Ok so there is a better way? if so how would I do this "loop" I don't want it to be a while 1 infinite loop because the func go() checks to see if a variable has changed or not before it runs itself all of the way... "however I need it to for sure run the first part even if that variable has not changed..."

Share this post


Link to post
Share on other sites

Post some more code, a better example of what you're trying to accomplish, because I don't understand.

Putting a loop in the Go function that calls Go would be more effective.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

21 minutes ago, InunoTaishou said:

Post some more code, a better example of what you're trying to accomplish, because I don't understand.

Putting a loop in the Go function that calls Go would be more effective.

Here is a retry at the code Will that work?

 

Go()

Func Go()
Do
;Do Stuff

If $Stop_Submit = 0 Then
;Do More Stuff
Else

Endif

$rand = Random(800, 1150)
$PIIM = ($rand * 60 * GUICtrlRead($Post_Interval_In_Minutes)) ; PIIM = Park Interval In Minutes Use RAND for variation so Server Time is Limited
$PIIMR = $PIIM / 60000 ; PIIMR = Park Interval In Minutes Recalculated (converted to minutes)
$continue = MsgBox(4, "Continue?", "Click NO To Stop Submission Proccess or Click YES To Continue Submitting . This Box Will Timeout And Continue Submitting In " & $PIIMR & " Minutes", $PIIMR)
If $continue = 7 Then
$Stop_Submit = 1
Else

EndIf

Until $Stop_Submit = 1
Endfunc

 

18 minutes ago, JohnOne said:

What you have there is called recursion. I'm sure it has its place, but I've never needed it.

If you use recursion wrong it will crash your script eventually, or AutoIt will end it.

Thanks for the terminology :D I think I found a simpler way.... :D That code up there is what I think might work... can either of you confirm for me?

Edited by rm4453
Fixed spelling error

Share this post


Link to post
Share on other sites

Nasty. It would work but idk why you wouldn't just return. I can't make your example work since I don't have your variables and the GUI, but maybe this will give you an idea.

Go()

Func Go()
    Local $iLoops = 0
    Local $iTimer = TimerInit()
    While (True)
        ConsoleWrite("Currently looped count: " & $iLoops & @LF)

        If (TimerDiff($iTimer) > 3000) Then
            If (MsgBox(4, "Continue?", "Would you like to continue looping?") = 7) Then
                Return ConsoleWrite("Finally exited that loop!" & @LF)
            Else
                ConsoleWrite("User opted to continue looping >.<" & @LF)
                $iTimer = TimerInit()
            EndIf
        EndIf

        Sleep(200)
        $iLoops += 1
    WEnd
EndFunc

 

Share this post


Link to post
Share on other sites
1 minute ago, InunoTaishou said:

Nasty. It would work but idk why you wouldn't just return. I can't make your example work since I don't have your variables and the GUI, but maybe this will give you an idea.

Go()

Func Go()
    Local $iLoops = 0
    Local $iTimer = TimerInit()
    While (True)
        ConsoleWrite("Currently looped count: " & $iLoops & @LF)

        If (TimerDiff($iTimer) > 3000) Then
            If (MsgBox(4, "Continue?", "Would you like to continue looping?") = 7) Then
                Return ConsoleWrite("Finally exited that loop!" & @LF)
            Else
                ConsoleWrite("User opted to continue looping >.<" & @LF)
                $iTimer = TimerInit()
            EndIf
        EndIf

        Sleep(200)
        $iLoops += 1
    WEnd
EndFunc

 

I kind of understand that... however I am using a Somewhat Random time that is based off of a user selection for the timeout interval "how long the message box will essentially "pause" the script while allowing the user to still stop it if need be..." That way It will only submit the information to the server when they need it to instead of over polling my system and their system... Your code is kind of confusing to me if you could explain to me how it works that would be very much appreciated! Thanks! (I also want them to be able to see when the next submission will occur so I will be including a timestamp for next submission)

Share this post


Link to post
Share on other sites

All my code does is infinitely loop (While (True)) until the user clicks "No" on the message box. I didn't want the MessageBox to pop up every milisecond so I put it on a timer for every 3 seconds. (TimerDiff($iTimer) > 3000, so when the difference between the current time and when the timer was started is greater than 3000.)

Once you hit "No" on the MessageBox then I return. This might be the part where you do your Stop and Submit stuff. If you hit "Yes" (to continue) then I reset the timer so you get another MessageBox in 3 minutes.

Share this post


Link to post
Share on other sites
6 minutes ago, InunoTaishou said:

All my code does is infinitely loop (While (True)) until the user clicks "No" on the message box. I didn't want the MessageBox to pop up every milisecond so I put it on a timer for every 3 seconds. (TimerDiff($iTimer) > 3000, so when the difference between the current time and when the timer was started is greater than 3000.)

Once you hit "No" on the MessageBox then I return. This might be the part where you do your Stop and Submit stuff. If you hit "Yes" (to continue) then I reset the timer so you get another MessageBox in 3 minutes.

Okay that makes a little bit more sense... Any way you could adapt it for me so I can see how I would implement it?

$PIIM = Park Interval In Minutes (How long to essentially stop the script and wait)

$Post_Interval_In_Minutes = How Long In Minutes The User Wanted To Have The Script Wait

$PIIM is calculated by getting a random number between 800 (aka 800 milliseconds) and 1150 (aka 1150 milliseconds) and multiplying by 60 and $Post_Interval_In_Minutes

$PIIMR is calculated by dividing PIIM by 60000 (60000 milliseconds = 1 minute)

Share this post


Link to post
Share on other sites

ERROR! I accidentally messed up my code! LOL Let me repost sorry guys... put actions in wrong area... XD *A DERPA DERP*

 

Go()

Func Go()
Do
;Do Stuff

If $Stop_Submit = 0 Then
    ;Do More Stuff

    $rand = Random(800, 1150)
    $PIIM = ($rand * 60 * GUICtrlRead($Post_Interval_In_Minutes)) ; PIIM = Park Interval In Minutes Use RAND for variation so Server Time is Limited
    $PIIMR = $PIIM / 60000 ; PIIMR = Park Interval In Minutes Recalculated (converted to minutes)
    $continue = MsgBox(4, "Continue?", "Click NO To Stop Submission Proccess or Click YES To Continue Submitting . This Box Will Timeout And Continue Submitting In " & $PIIMR & " Minutes", $PIIMR)
    
        If $continue = 7 Then
        $Stop_Submit = 1
    Else

    EndIf

Else

Endif

Until $Stop_Submit = 1
Endfunc

Sorry bout that guys... I misplaced where the code should have gone :sweating:

Share this post


Link to post
Share on other sites

Something like this maybe

Go()

Func Go()
    Local $Post_Interval_In_Minutes = 1
    Local $Stop_Submit = False

    While (Not $Stop_Submit)
        ; Random number between 800 and 1150 * 60 * the minutes read from the GUI Control, then converted to minutes
        Local $rand = Random(800, 1150)
        Local $PIIM = ($rand * 60 * $Post_Interval_In_Minutes) ; PIIM = Park Interval In Minutes Use RAND for variation so Server Time is Limited
        Local $PIIMR = $PIIM / 60000 ; PIIMR = Park Interval In Minutes Recalculated (converted to minutes)

        If (MsgBox(4, "Continue?", "Click NO To Stop Submission Proccess or Click YES To Continue Submitting . This Box Will Timeout And Continue Submitting In " & $PIIMR & " Minutes", $PIIMR) = 7) Then
            $Stop_Submit = True
        Else
            ConsoleWrite("Continue Submitting" & @LF)
        EndIf
    WEnd

    ConsoleWrite("Stop Submitting" & @LF)
EndFunc   ;==>Go

You've got the wrong Timeout for MsgBox though.

Share this post


Link to post
Share on other sites
5 minutes ago, InunoTaishou said:

Something like this maybe

Go()

Func Go()
    Local $Post_Interval_In_Minutes = 1
    Local $Stop_Submit = False

    While (Not $Stop_Submit)
        ; Random number between 800 and 1150 * 60 * the minutes read from the GUI Control, then converted to minutes
        Local $rand = Random(800, 1150)
        Local $PIIM = ($rand * 60 * $Post_Interval_In_Minutes) ; PIIM = Park Interval In Minutes Use RAND for variation so Server Time is Limited
        Local $PIIMR = $PIIM / 60000 ; PIIMR = Park Interval In Minutes Recalculated (converted to minutes)

        If (MsgBox(4, "Continue?", "Click NO To Stop Submission Proccess or Click YES To Continue Submitting . This Box Will Timeout And Continue Submitting In " & $PIIMR & " Minutes", $PIIMR) = 7) Then
            $Stop_Submit = True
        Else
            ConsoleWrite("Continue Submitting" & @LF)
        EndIf
    WEnd

    ConsoleWrite("Stop Submitting" & @LF)
EndFunc   ;==>Go

You've got the wrong Timeout for MsgBox though.

Saw that and am fixing it Thanks ! I will look at your code and see if I can figure it out and all that Thanks so much! :lmao:

Share this post


Link to post
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

  • Similar Content

    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • WiorDi37
      By WiorDi37
      Hello, Everyone!
      I want when clicking the exit button the window will close. If content changes upon exit the program will automatically choose not save.
      Look forward to the help, thanks.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> $GUI = GUICreate("Form1", 220, 119, 192, 124, $WS_SYSMENU) GUISetFont(10, 400, 0, "Tahoma") GUICtrlCreateGroup("Chuẩn bị trình chiếu", 16, 16, 185, 65) $ok_Button = GUICtrlCreateButton("Ok", 32, 48, 75, 25) $exit_Button = GUICtrlCreateButton("Exit", 112, 48, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $ok_Button ShellExecute(@MyDocumentsDir&'\Dich-thuat\Short-Document.pdf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Data and Computer Communications (Eighth Edition) - Google Chrome") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Document.rtf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Document.rtf [Compatibility Mode] - Word") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Presentation1.pptx', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Presentation1.pptx - PowerPoint") MouseClick("left", 1381, 886, 1) Sleep(2000) MsgBox(64, "Thông báo", "Đã chuẩn bị xong") Case $exit_Button WinClose("Presentation1.pptx - PowerPoint") ;I need help handling this place Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  

    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?