Jump to content
Sign in to follow this  
x0t

Loop Help

Recommended Posts

x0t

So, I'm playing around with things I can do. I wanted to make this app just do as it does for the most part, but make one function checking if I hit the close button. I wouldn't mind understanding a more simple way to do this, but the point of this is so that I can later on make a GUI app with multiple functions, that have pretty much one "controller" type that does a check of all the buttons, while the rest of the application can work. Maybe to be passed back to whatever function called it, I dont know if I can but, i'm attempting it.

; tests
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
global  $msg, $x, $y
$msg = GUIGetMsg()
$x=500
$y=300
start()
func start()
GuiCreate("test", $x, $y)
GUISetState()
work()
endfunc
Func work()
local $chk1, $chk2, $a, $b, $c
Sleep(100)
while 1
  $c=(Random(25,475))
  $b=(Random(25,275))
  GUICtrlCreateLabel("test" &$a, $c, $b, 25, 25)
  sleep(100)
  monitor()
WEnd
EndFunc
func monitor() ;trying to make this function check if I hit the close button if so close, if not return back to the other function.
local $a, $b, $c
while 1
  Select
   Case $msg = $GUI_EVENT_CLOSE
   GuiDelete()
  EndSelect
  sleep(100)
  work()
wend
EndFunc

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the autoit forum =)

You are using the GUIGetMsg function in a wrong context.

I'm sure you have not took a look at the help file for this function. I suggest you to take a look at the example included with the GUICreate function and you will understand how the GUIGetMsg function works. (you have also OnEvent parameters with the GUIOnEventMode opt set to 1).

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
x0t

I don't think you really understand what I am doing here, I double checked the GUICreate and GUIGetMsg like you requested, and even trying to apply how it explains and shows how to use them, it's not working for me. Note, that I do want it to repeat putting "test" all over the GUI. I am capable of making it work when working as a singular function, I'm having trouble keeping it multi-function with them passing functionality back and forth.

Share this post


Link to post
Share on other sites
guinness

Look in the wiki for multiple GUIs. FireFox understands, just you misread the help file on how GUIGetMsg works.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
x0t

Okay, maybe I'm just missing something here. I looked at the Wiki for multiple GUIs but I didn't see it, note - that I do not want more than one GUI, though, just multiple functions working together.

So, I took the example for GUIGetMsg and used it.

#include <GUIConstantsEx.au3>
Example()
;-------------------------------------------------------------------------------------
; Example - Press the button to see the value of the radio boxes
; The script also detects state changes (closed/minimized/timeouts, etc).
Func Example()
Local $button_1, $radio_1, $radio_3
Local $radioval1, $msg
Opt("GUICoordMode", 1)
GUICreate("Radio Box Demo", 400, 280)
; Create the controls
$button_1 = GUICtrlCreateButton("B&utton 1", 30, 20, 120, 40)
GUICtrlCreateGroup("Group 1", 30, 90, 165, 160)
GUIStartGroup()
$radio_1 = GUICtrlCreateRadio("Radio &0", 50, 120, 70, 20)
GUICtrlCreateRadio("Radio &1", 50, 150, 60, 20)
$radio_3 = GUICtrlCreateRadio("Radio &2", 50, 180, 60, 20)
$button_x = GUICtrlCreateButton("Switch Functions", 200, 20, 120, 40)
$button_q = GUICtrlCreateButton("Quit", 200, 80, 120, 40)
; Init our vars that we will use to keep track of GUI events
$radioval1 = 0 ; We will assume 0 = first radio button selected, 2 = last button
; Show the GUI
GUISetState()
; In this message loop we use variables to keep track of changes to the radios, another
; way would be to use GUICtrlRead() at the end to read in the state of each control
While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    MsgBox(0, "", "Dialog was closed")
    Exit
   Case $msg = $GUI_EVENT_MINIMIZE
    MsgBox(0, "", "Dialog minimized", 2)
   Case $msg = $GUI_EVENT_MAXIMIZE
    MsgBox(0, "", "Dialog restored", 2)
   Case $msg = $button_1
    MsgBox(0, "Default button clicked", "Radio " & $radioval1)
   Case $msg >= $radio_1 And $msg <= $radio_3
    $radioval1 = $msg - $radio_1
   Case $msg = $button_x
    test()
   Case $msg = $button_q
    GUIDelete()
  EndSelect
WEnd
EndFunc   ;==>Example
Func test()
Local $a, $b, $c
Sleep(100)
While 1
  $c = (Random(25, 500))
  $b = (Random(25, 300))
  GUICtrlCreateLabel("test" & $a, $c, $b, 25, 25)
  Sleep(500)
WEnd
EndFunc   ;==>test

This is the exact code from the example with an added blah function to write test all over the gui. My goal, is to while its writing "test" all over the screen, to still be able to quit the application to use the X or "Quit" buttons I created. If you note, in my other script up above, I did add the GUIGetMsg and a Select loop to find out if X was pressed in my first script to both my functions, and that did not work. This doesn't work but I know it shouldn't since the check for buttons isnt in the test() function. I know it's ignorant as hell, but I am really not understanding that helpfile on GUIGetMsg compared to what I am doing and why it would be wrong.

Share this post


Link to post
Share on other sites
kylomas

x0t,

The closest that you are going to get to asynchronous execution using functions is to run test() as an adlib. However, do you really want to be creating labels at random places, assumming that it works at all (your random limits do not match your gui bounds)?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
x0t

x0t,

The closest that you are going to get to asynchronous execution using functions is to run test() as an adlib. However, do you really want to be creating labels at random places, assumming that it works at all (your random limits do not match your gui bounds)?

kylomas

Thank you kylamos, I was looking at other posts and saw something about adlib I was just opening the help file when I read this, I'll give that a shot and hope it works out. And in all honesty, I have other projects I am working on and work pretty well, but having the functions be asnychronous as you said has been the first thing that gave me an issue. This is actually a dummy script, I actually didn't even think about the limits of the gui when I messed with this at all, I just wrote something fast up that would explain my needs in an easy manner so that I don't have to post a ton of script and it be all complicated (not including how complicated I made this already lol)

SO

That pretty much summed up what I needed, the adlib thing that is, I'll give it a shot as I said, thanks again.

Share this post


Link to post
Share on other sites
kylomas

x0t,

Your welcome.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
x0t

Okay so, going back to the script I used in the original post, and trying to make use of the AdlibRegister feature;

; tests on asynchronous functioning
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $msg, $x, $y
$msg = GUIGetMsg()
$x = 500
$y = 300
start()
Func start()
GUICreate("test", $x, $y)
GUISetState()
AdlibRegister("monitor")
work()
EndFunc ;==>start
Func work()
Sleep(100)
While 1
$c = (Random(25, 475))
$b = (Random(25, 275))
GUICtrlCreateLabel("test" & $a, $c, $b, 25, 25)
Sleep(100)
WEnd
EndFunc ;==>work
Func monitor() ;trying to make this function check if I hit the close button if so close, if not return back to the other function.
Local $a, $b, $c
While 1
Select
Case $msg = $GUI_EVENT_CLOSE
    GUIDelete()
EndSelect
Sleep(500)
work()
WEnd
EndFunc ;==>monitor

So, now it works just as before but I do know the adlib is calling monitor(), I had to add the work() call in it just to make sure it kept printing "test" lol.

Problem still exists though how it's not either a) recognizing the close button is being pressed or B) actually checking for it.

I even increased the sleep before monitor() recalls work() just so that it may stand a better chance. Advice?

Edited by x0t

Share this post


Link to post
Share on other sites
BrewManNH

The point FireFox was making is that your GUIGetMsg function is in the wrong place in your script, you're only checking it once.

;~  tests
#include 
#include 
Global $msg, $x, $y
; $msg = GUIGetMsg()  don't read it here, it's not reading anything anyways.
$x = 500
$y = 300
start()
Func start()
    GUICreate("test", $x, $y)
    GUISetState()
    work()
EndFunc   ;==>start
Func work()
    Local $chk1, $chk2, $a, $b, $c
    Sleep(100)
    While 1
        $c = (Random(25, 475))
        $b = (Random(25, 275))
        GUICtrlCreateLabel("test" & $a, $c, $b, 25, 25)
        monitor()
        Sleep(100)
    WEnd
EndFunc   ;==>work
Func monitor() ;trying to make this function check if I hit the close button if so close, if not return back to the other function.
    Local $a, $b, $c
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
        EndSelect
EndFunc   ;==>monitor

BTW, using autoit tags instead of Code tags makes your code a lot easier to read.

Edited by BrewManNH

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
kylomas

x0t,

What exactly are you trying to do?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
kylomas

x0t,

This seems to do what you want, however, what you are doing make NO sense to me.

; tests on asynchronous functioning
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $msg, $x, $y
$x = 500
$y = 300
GUICreate("test", $x, $y)
GUISetState()
;AdlibRegister("monitor")

while 1
    switch guigetmsg()
        case $GUI_EVENT_CLOSE
            Exit
    endswitch

    work()

wend

Func work()
    Sleep(100)
    While 1
        $a = (Random(25, 475))
        $c = (Random(25, 475))
        $b = (Random(25, 275))
        GUICtrlCreateLabel("test" & $a, $c, $b, 25, 25)
        ;Sleep(100)
        return
    WEnd
EndFunc   ;==>work

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
x0t

@kylomas; if I were attempting to use only a single function for my application this would work, but remember as I said in my first post, this is a dummy application to help me learn to use multiple functions - thats why the functions pass back to each other - but what I need to do is still be able to close application once the functions are in process.

@BrewManNH; the changes you made to the original script gave me the following error:

x:\autoit\tests\tests.au3(29,41) : WARNING: $GUI_EVENT_CLOSE: possibly used before declaration.
E:\autoit\tests\tests.au3(29,41) : ERROR: $GUI_EVENT_CLOSE: undeclared global variable.
Edited by x0t

Share this post


Link to post
Share on other sites
FireFox

x:\autoit\tests\tests.au3(29,41) : WARNING: $GUI_EVENT_CLOSE: possibly used before declaration.
E:\autoit\tests\tests.au3(29,41) : ERROR: $GUI_EVENT_CLOSE: undeclared global variable.

:rolleyes: this is a global constant included in the GUIConstantsEx file.

#include <GUIConstantsEx.au3>

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
guinness

That's also the Forum stripping includes not BrewManNH forgetting to include.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
x0t

Now I feel slow, sorry about that and thanks BrewManNH, that worked. Going to apply it for my other projects, and sorry to the rest about being so complicated over learning something simple xD

Share this post


Link to post
Share on other sites
kylomas

x0t,

If your programming paradigm is to create several functions, each one calling a function to check on control actions, then I would suggest that you re-think the structure. My opinion is that this will cause the app to become unresponsive and a maintenance nightmare.

If I'm full of shit, please enlighten.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  

×