Jump to content

AdlibRegister for 2 Func


Recommended Posts

Hi guys,

I'dl like to use the same AdlibRegister for to different function. That's an example:

#include <GUIConstantsEx.au3>

Global $hButton3 = 9999, $Increase = 0, $hGUI1

gui1()

Func gui1()
$hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
$hButton1 = GUICtrlCreateButton("Adlib1", 10, 10, 80, 30)
$hButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
GUISetState()

While 1
  Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $hButton1
    AdlibRegister("Test", 400)
    Sleep(2000)
    AdlibUnRegister("Test")
    WinSetTitle($hGUI1, "", "Gui 1")
   Case $hButton2
    GUICtrlSetState($hButton2, $GUI_DISABLE)
    gui2()
   Case $hButton3
    AdlibRegister("Test", 400)
    Sleep(2000)
    AdlibUnRegister("Test")
    WinSetTitle($hGUI1, "", "Gui 1")
  EndSwitch
WEnd
EndFunc   ;==>gui1

Func gui2()
$hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
$hButton3 = GUICtrlCreateButton("Adlib2", 10, 10, 80, 30)
GUISetState()
EndFunc   ;==>gui2

Func Test()
Switch Mod($Increase, 4)
  Case 0
   WinSetTitle($hGUI1, "", "... A")
  Case 1
   WinSetTitle($hGUI1, "", "... B")
  Case 2
   WinSetTitle($hGUI1, "", "... C")
  Case 3
   WinSetTitle($hGUI1, "", "... D")
EndSwitch
$Increase += 1
EndFunc   ;==>Test

I have try to make an handle like:

Func Test($handle)
Switch Mod($Increase, 4)
  Case 0
   WinSetTitle($handle, "", "... A")
  Case 1
   WinSetTitle($handle, "", "... B")
  Case 2
   WinSetTitle($handle, "", "... C")
  Case 3
   WinSetTitle($handle, "", "... D")
EndSwitch
$Increase += 1
EndFunc   ;==>Test
[autoit]

and make:
[autoit] 
AdlibRegister("Test(" & $hGUI1 & ")",400)

But not work, some advice?

Thanks ;)

Link to comment
Share on other sites

You can't pass parameters to Adlibregister. Hence

AdlibRegister("Test(" & $hGUI1 & ")",400)
won't work.

The way you use AdLibRegister (register, wait a few seconds and unregister in a loop) I would simply call test as a function.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

So, if i have understad well, i can't call the same Test() for two different function?

I need to create two different like:

Func Test_GUI1()
Switch Mod($Increase, 4)
Case 0
WinSetTitle($hGUI1, "", "... A")
Case 1
WinSetTitle($hGUI1 "", "... B")
Case 2
WinSetTitle($hGUI1, "", "... C")
Case 3
WinSetTitle($hGUI1, "", "... D")
EndSwitch
$Increase += 1
EndFunc
 
Func Test_GUI2()
Switch Mod($Increase, 4)
Case 0
WinSetTitle($hGUI2, "", "... A")
Case 1
WinSetTitle($hGUI2, "", "... B")
Case 2
WinSetTitle($hGUI2, "", "... C")
Case 3
WinSetTitle($hGUI2, "", "... D")
EndSwitch
$Increase += 1
EndFunc

There isn't a workaround?

Edited by johnmcloud
Link to comment
Share on other sites

You can use AdLibRegister for two different functions. But the way you use AdLibRegister doesn't make sense. Simply call Test() and pass parameters if needed.

AdLibRegister is used to call a function every x milliseconds while the main script keeps on processing.

You register the function, Sleep and then unregister the function. That's not what AdLibRegister should be used for.

Is this a real life problem you try to solve or do you just play around?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You don't need two functions, just drop AdLiBRegister.

#include <GUIConstantsEx.au3>

Global $hButton3 = 9999, $Increase = 0, $hGUI1

gui1()

Func gui1()
    $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
    $hButton1 = GUICtrlCreateButton("Adlib1", 10, 10, 80, 30)
    $hButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hButton1
                Test($hGUI1)
                Sleep(2000)
                WinSetTitle($hGUI1, "", "Gui 1")
            Case $hButton2
                GUICtrlSetState($hButton2, $GUI_DISABLE)
                gui2()
            Case $hButton3
                Test($hGUI1)
                Sleep(2000)
                WinSetTitle($hGUI1, "", "Gui 1")
        EndSwitch
    WEnd
EndFunc   ;==>gui1

Func gui2()
    $hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
    $hButton3 = GUICtrlCreateButton("Adlib2", 10, 10, 80, 30)
    GUISetState()
EndFunc   ;==>gui2

Func Test($hGUI)
    Switch Mod($Increase, 4)
        Case 0
            WinSetTitle($hGUI, "", "... A")
        Case 1
            WinSetTitle($hGUI, "", "... B")
        Case 2
            WinSetTitle($hGUI, "", "... C")
        Case 3
            WinSetTitle($hGUI, "", "... D")
    EndSwitch
    $Increase += 1
EndFunc   ;==>Test

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...