Sign in to follow this  
Followers 0
tommytx

Empty function run normal but the regular function is screwey...

7 posts in this topic

I thinks I am losing my mind... again... can someone help me out here... when I use the

if you notice in the while loop below i have the empty function commented out... but when I run with the normal function say for example the button for DoSync() not only does it DoSync but also falls thru and does the next one DoTes() also... then gones into a loop over and over on the last entry DoTest()

When I comment out the first one.. DoStart() and allow the DoStart1() empty funciton to run all is well it only goes to the selected one... what the heck am I missing here... it should be simple..

DoStart()

; DoStart1()

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Dim $start, $mgs, $nrsecs, $nrtorun, $i, $tot
Dim $mytime, $nrwins, $num, $secdelay, $file, $dog, $i, $sync, $cat, $test

#Region ### START Koda GUI section ### Form=C:\koda-form-designer\koda_1.7.2.0\Forms\form3x.kxf
;                                         W    H    L    T
$Form1_1 = GUICreate("Hud Alert Control", 378, 303, 750, 0)
$Tab1 = GUICtrlCreateTab(16, 32, 337, 249)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$StartUp = GUICtrlCreateTabItem("StartUp")
$Group1 = GUICtrlCreateGroup("Start Up", 32, 72, 297, 185)
$Label1 = GUICtrlCreateLabel("Number of Instances to Run", 72, 136, 137, 17)
$nrtorun = GUICtrlCreateInput("4", 224, 136, 57, 21)
$Label2 = GUICtrlCreateLabel("Number of seconds apart ", 72, 176, 126, 17)
$nrsecs = GUICtrlCreateInput("60", 224, 176, 57, 21)
$start = GUICtrlCreateButton("Start Now!", 136, 216, 97, 25, $WS_GROUP)
$Label3 = GUICtrlCreateLabel("Select the total number of instances to run 1-16.", 72, 96, 230, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$TabSheet2 = GUICtrlCreateTabItem("Sync")
$sync = GUICtrlCreateButton("Begin Sync", 104, 136, 145, 25, $WS_GROUP)
$TabSheet3 = GUICtrlCreateTabItem("Test")
$test = GUICtrlCreateButton("Begin Test", 104, 136, 145, 25, $WS_GROUP)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
   Case $msg = $start
    Msgbox(0,"","At the DoStart now.")
    DoStart()
    ; DoStart1()
            Case $msg = $sync
    Msgbox(0,"","At the DoSync now.")
    DoSync()
    ;DoSync1()
            Case $msg = $test
    Msgbox(0,"","At the DoTest now.")
    DoTest()
    ; DoTest1()
   
   EndSelect
  
    WEnd

Func DoStart1()
EndFunc
Func DoSync1()
EndFunc
Func DoTest1()
EndFunc

Func DoStart()
Local $x
$nrtorun = GUICtrlRead($nrtorun)
$nrsecs = GUICtrlRead($nrsecs) * 100
for $i = 1 to $nrtorun
Run(@ScriptDir & "\sec_half_size.exe")
for $x = 1 to 10
  Sleep($nrsecs)
Next
Next
EndFunc

Func DoSync()
$mytime = 13
$secdelay = 20
$nrwins = 4
$test = 0
$num = 0
if $mytime > 0 then $num = round(($mytime/$nrwins), 1)
for $i = 1 to $nrwins
$dog = $num * $i & "|" & $secdelay & "|" & $test & "|"
$cat = $cat & $dog & @CRLF
;$sync = @ScriptDir & "\sync" & $i & ".txt"
;$file = FileOpen($sync, 2)
;FileWriteLine($file, $dog)
;FileClose($file)
Next
MsgBox(0, "", $cat)
EndFunc

Func DoTest()
$nnrwins = 1
for $i = 1 to $nrwins
$dog = "0|0|1|"
msgbox(0,"",$dog)
; $sync = @ScriptDir & "\sync" & $i & ".txt"
; $file = FileOpen($sync, 2)
; FileWriteLine($file, $dog)
; FileClose($file)
Next
EndFunc

Share this post


Link to post
Share on other sites



Here's your problem:

Func DoSync()
 $mytime = 13
 $secdelay = 20
 $nrwins = 4
 $test = 0 ; you reset the value of $test to 0, which is the default return from GUIGetMsg if nothing is happening on the GUI, declare your local variables as Local or use another name for it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks for that Brewaman, making $test a local variable solved the problem,... but I have something else wrong that you may be able to see what is wrong....

In the example above I have shown the DoStart() function again here since anytime I run the DoStart() function, it locks out all the other menu items until the exe shutsdown... I an not using RunWait() so I do not understand why the system is waiting for the shut down of any exec files before any other routines can be run... Baiscally lockup up the control panel so none of the other subs can be run until the Dostart() execs have shut down... is there a better command than Run that I can use to start an exec file that will not hang up my other Menu Items...Thanks.... I am getting some really strange problems here now..

Func DoStart()
Local $x
$nrtorun = GUICtrlRead($nrtorun)
$nrsecs = GUICtrlRead($nrsecs) * 100
for $i = 1 to $nrtorun
Run(@ScriptDir & "sec_half_size.exe")
for $x = 1 to 10
  Sleep($nrsecs)
Next
Next
EndFunc

Share this post


Link to post
Share on other sites

I'm not sure why it is hanging, but one thing to look at, now and in all further coding, is declaring your variables and declaring them in the proper scope. You are reusing variable names in your functions, but not using Local to declare which causes the loss of the controlIDs that were in them before. If your variables are not in a function, declare them using Global, if they're in a function, declare them using Local. Don't use Dim to declare your variables though because you'll end up screwing everything up with variable names again.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

In addition to what BrewManNH said, you have to realize that while a function is being executed, nothing is happening in your main While loop. Reading and reacting to GUIGetMsg() in the main loop is what allows your GUI to work, so nothing is going to happen until you get back to your main loop. Also note that any GUI interactions while your function is running ARE QUEUED. So when that function returns, the queued messages are processed in the order they were received. That means if you hit a button that triggers your DoStart() function 10 times, well, it's going to run 10 times.

Share this post


Link to post
Share on other sites

I was under the impression that when I used the RunWait() command then everything sits and waits until the program you just ran completes... but if you did not use the Wait then the calling program kept on running.... Matter of fact I assumed that is what the Wait was designed for... to make the main program wait for the called program to complete before it moved on... but would otherwise move on if the wait command was not initiated...

So is there any command that I can use to run an external program that will allow my script to keep going....

Maybe I need to do something like this...

Inside a .bat file call the external program and call the .bat file without the run wait... will that work... I will try it..

Share this post


Link to post
Share on other sites

Not sure what I did or what happened... but its working fine now.... Thanks for all the suggestions.

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
Sign in to follow this  
Followers 0