Jump to content

Execute the function only once


Recommended Posts

#Include <GUIConstants.au3>
#include <ColorConstants.au3>
#include <MsgBoxConstants.au3>
#include <Sound.au3>

$mEndpoint_ABS = GUICtrlCreateMenuItem("&Endpoint", $mABS)
    GUICtrlSetOnEvent(-1, "tab_ABS")
    
Func tab_ABS()
    Opt("GUIOnEventMode", 1)
    Local $idTab = GUICtrlCreateTab(0, 10, 620, 355)    
            GUICtrlCreateTabItem("Plate Type")
            GUICtrlCreateTabItem("Shake")
            GUICtrlCreateTabItem("More Settings")
            GUICtrlCreateTabItem("")
EndFunc
How can I have the function executed only once so that I do not have to create a large number of different tabs every time I click on "Endpoint"?
( It's just an excerpt from the script)
Link to comment
Share on other sites

Use static, then things are initialized only once:

#Include <GUIConstants.au3>
#include <ColorConstants.au3>
#include <MsgBoxConstants.au3>
#include <Sound.au3>

Opt("GUIOnEventMode", 1)

$mEndpoint_ABS = GUICtrlCreateMenuItem("&Endpoint", $mABS)
    GUICtrlSetOnEvent(-1, "tab_ABS")
    
Func tab_ABS()
    Local Static $idTab = GUICtrlCreateTab(0, 10, 620, 355)    
            GUICtrlCreateTabItem("Plate Type")
            GUICtrlCreateTabItem("Shake")
            GUICtrlCreateTabItem("More Settings")
            GUICtrlCreateTabItem("")
EndFunc

 

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@jchd That won't work because GUICtrlCreateTabItem must also be Static.

I would rather advise OP to create the tab once at the beginning of the script and not based on an event.  Hide the control if needed, and show it when required.

Link to comment
Share on other sites

Ah! Sorry the indentation led me to think it was a one-liner but I didn't check for commas and continuation.

Note to self: don't quick-post answers while discussing completely unrelated tech matters over the phone at the same time!

EDIT: JD = jchd + 9 I don't get it

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Sorry guys, I'm still a beginner and don't know how to implement the suggestions. "Static" did not work, but I was able to call the function several times and again had the problem of creating an infinite number of tabs.

 

Link to comment
Share on other sites

Read what was posted, you need static for every declaration you want to be one-shot:

#include <GUIConstants.au3>
#include <ColorConstants.au3>
#include <MsgBoxConstants.au3>
#include <Sound.au3>

Opt("GUIOnEventMode", 1)

Local $mEndpoint_ABS = GUICtrlCreateMenuItem("&Endpoint", $mABS)
GUICtrlSetOnEvent(-1, "tab_ABS")

Func tab_ABS()
    Local Static $idTab = GUICtrlCreateTab(0, 10, 620, 355)
    Local Static $idT1 = GUICtrlCreateTabItem("Plate Type")
    Local Static $idT2 = GUICtrlCreateTabItem("Shake")
    Local Static $idT3 = GUICtrlCreateTabItem("More Settings")
    Local Static $idT4 = GUICtrlCreateTabItem("")
EndFunc

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Note that local variables are only visible from inside the function where they are declared. Static means: "initialize me only once"

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

9 minutes ago, jchd said:

Note that local variables are only visible from inside the function where they are declared.

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Impossible to help without code.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

#Include <GUIConstants.au3>
#include <ColorConstants.au3>
#include <MsgBoxConstants.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1)

;Aufrufen der Funktionen
gui_settings()

Func gui_settings()
    $Settings = GUICreate("Settings", 615, 438, 192, 124)
    $mFile = GUICtrlCreateMenu("&File")
    $mOpen = GUICtrlCreateMenuItem("&Open", $mFile)
    GUICtrlSetOnEvent(-1, "open")
    $mSaveas = GUICtrlCreateMenuItem("&Save", $mFile, 1)
    GUICtrlSetOnEvent(-1,"save")
    GUICtrlSetState(-2, $GUI_DEFBUTTON)
    GUICtrlCreateMenuItem("", $mFile, 4)
    $mExit = GUICtrlCreateMenuItem("&Exit", $mFile)
    GUICtrlSetOnEvent(-1, "ende")
    $mABS = GUICtrlCreateMenu("&ABS")
    $mEndpoint_ABS = GUICtrlCreateMenuItem("&Endpoint", $mABS)
;~  GUICtrlSetOnEvent(-1, "tab_ABS")
    $mKinetic_ABS = GUICtrlCreateMenu("&Kinetic", $mABS)
    $mWellScan_ABS = GUICtrlCreateMenu("&Well Scan", $mABS)
    $mSpectrum_ABS = GUICtrlCreateMenu("&Spectrum", $mABS)
    $mFRET = GUICtrlCreateMenu("&FRET")
    $mEndpoint_FRET = GUICtrlCreateMenuItem("&Endpoint", $mFRET)
;~  GUICtrlSetOnEvent(-1, "tab_FRET")
    $mKinetic_FRET = GUICtrlCreateMenu("&Kinetic", $mFRET)
    $mWellScan_FRET = GUICtrlCreateMenu("&Well Scan", $mFRET)
    $mLUM = GUICtrlCreateMenu("&LUM")
    $mEndpoint_LUM = GUICtrlCreateMenuItem("&Endpoint", $mLUM)
    GUICtrlSetOnEvent(-1, "tab_LUM")
    $mKinetic_LUM = GUICtrlCreateMenu("&Kinetic", $mLUM)
    $mWellScan_LUM = GUICtrlCreateMenu("&Well Scan", $mLUM)
    $mSpectrum_LUM = GUICtrlCreateMenu("&Spectrum", $mLUM)
    $mFragezeichen = GUICtrlCreateMenu("&?")
    $mHelp_Fragezeichen = GUICtrlCreateMenuItem("Help" & @TAB & "F1", $mFragezeichen)
    GUICtrlSetOnEvent(-1, "help")
    $Button_Cancel = GUICtrlCreateButton("Cancel", 450, 370, 70, 20)
    GUICtrlSetOnEvent(-1, "ende")
    $Button_OK = GUICtrlCreateButton("OK", 530, 370, 70, 20)
    GUICtrlSetOnEvent(-1, "ende")
    GUISetOnEvent($GUI_EVENT_CLOSE, "ende")
    GUISetState(@SW_SHOW)
    While 1
    Sleep(10)
    WEnd
    GUISetState(@SW_HIDE)
EndFunc

Func ende()
    Exit
EndFunc

Func help()
    MsgBox(289, "Help", "Just ask Annika.")
EndFunc

Func open()
    FileOpenDialog(" Open some File...", @WindowsDir, "All(*.*)")
EndFunc

Func save()
    Local $sFileSaveDialog = FileSaveDialog("Save as", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Scripts (*.au3)", $FD_PATHMUSTEXIST)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "No file was saved.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "You saved the following file:" & @CRLF & $sFileSaveDialog)
    EndIf
EndFunc
Func tab_LUM() ; FEHLER: Es lässt unendlich viele Tabs erstellen
    Local Static $idTab = GUICtrlCreateTab(0, 10, 620, 355)
            Local Static $wave = GUICtrlCreateTabItem("Wavelengths")
            Local Static $Label_NumberW = GUICtrlCreateLabel("Number of Wavelenghts:", 10, 40, 170, 20)
            Local Static $Input_Wavelenghts = GUICtrlCreateInput("", 150, 37, 70, 20)
            GUICtrlCreateUpdown($Input_Wavelenghts)
            Local Static $Label_Lm1 = GUICtrlCreateLabel("Lm1", 120, 70, 20, 20)
            Local Static $Input_Lm1 = GUICtrlCreateInput("", 150, 67, 70, 20)
            Local Static $Label_nm = GUICtrlCreateLabel("nm", 230, 70, 70, 20)
            Local Static $Pic_Spektrum = GUICtrlCreatePic("C:\Users\Admin\Pictures\Spektrum.jpg", 10, 100, 500, 150)
            Local Static $Button_700nm = GUICtrlCreateButton ("700 nm", 35, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0xFF0000)
            Local Static $Button_650nm = GUICtrlCreateButton ("650 nm", 100, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0xFFA500 )
            Local Static $Button_600nm = GUICtrlCreateButton ("600 nm", 165, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0xFFFF00)
            Local Static $Button_550nm = GUICtrlCreateButton ("550 nm", 230, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0x008000)
            Local Static $Button_500nm = GUICtrlCreateButton ("500 nm", 295, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0x0000FF)
            Local Static $Button_450nm = GUICtrlCreateButton ("450 nm", 360, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0x191970)
            GUICtrlSetColor(-2, 0xFFFFFF)
            Local Static $Button_400nm = GUICtrlCreateButton ("400 nm", 430, 210, 50, 20)
            GUICtrlSetBkColor(-1, 0xEE82EE)
            GUISetState(@SW_SHOW)
            Local Static $PlateType = GUICtrlCreateTabItem("Plate Type")
            Local Static $Label_NumberP = GUICtrlCreateLabel("Number of Plates:", 10, 40, 109, 20)
            Local Static $Input_NumberP = GUICtrlCreateInput("", 120, 37, 70, 20)
            GUICtrlCreateUpdown($Input_NumberP)
            Local Static $Group_Plate_Bottom = GUICtrlCreateGroup("", 5, 55, 230, 130)
            Local Static $Label_Plate_Bottom = GUICtrlCreateLabel ("Choose Platebottom:", 10, 70, 109, 20)
            Local Static $Radio_PlateAuswahl_U = GUICtrlCreateRadio ("96-U", 120, 70, 50, 20)
            Local Static $Radio_PlateAuswahl_V = GUICtrlCreateRadio ("96-V", 120, 100, 50, 20)
            Local Static $Radio_PlateAuswahl_F = GUICtrlCreateRadio ("96-F", 120, 130, 50, 20)
            Local Static $Radio_PlateAuswahl_C = GUICtrlCreateRadio ("96-C", 120, 160, 50, 20)
            Local Static $Group_Plate_Bottom = GUICtrlCreateGroup("", 5, 175, 230, 130)
            Local Static $Label_PlateMaterial = GUICtrlCreateLabel ("Plate material:", 10, 190, 109, 20)
            Local Static $Radio_highbinding = GUICtrlCreateRadio("high-binding", 120, 190, 100, 20)
            Local Static $Radio_normalbinding = GUICtrlCreateRadio("normal-binding", 120, 220, 100, 20)
            Local Static $Radio_notbinding = GUICtrlCreateRadio("not-binding", 120, 250, 100, 20)
            Local Static $ReadArea = GUICtrlCreateTabItem("Read Area")
            Local Static $Checkbox_allWells = GUICtrlCreateCheckbox("Select All", 545, 45, 97, 17)
            Local Static $Pic_Wellplate = GUICtrlCreatePic("C:\Users\Admin\Pictures\Wellplatepic.jpg", 70, 60, 467, 300)
            Local Static $Button_A = GUICtrlCreateButton ("A->", 35, 110, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_A")
            Local Static $Button_B = GUICtrlCreateButton ("B->", 35, 155, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_B")
            Local Static $Button_C = GUICtrlCreateButton ("C->", 35, 200, 40, 20)
            Local Static $Button_D = GUICtrlCreateButton ("D->", 35, 245, 40, 20)
            Local Static $Button_E = GUICtrlCreateButton ("E->", 35, 290, 40, 20)
            Local Static $Button_F = GUICtrlCreateButton ("F->", 35, 335, 40, 20)
            Local Static $Button_1 = GUICtrlCreateButton ("1", 125, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_1")
            Local Static $Button_2 = GUICtrlCreateButton ("2", 175, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_2")
            Local Static $Button_3 = GUICtrlCreateButton ("3", 225, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_3")
            Local Static $Button_4 = GUICtrlCreateButton ("4", 275, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_4")
            Local Static $Button_5 = GUICtrlCreateButton ("5", 325, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_5")
            Local Static $Button_6 = GUICtrlCreateButton ("6", 375, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_6")
            Local Static $Button_7 = GUICtrlCreateButton ("7", 425, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_7")
            Local Static $Button_8 = GUICtrlCreateButton ("8", 475, 45, 40, 20)
;~              GUICtrlSetOnEvent(-1,"Bereich_8")
            Local Static $PTMandOptics = GUICtrlCreateTabItem("PTM and Optics")
            Local Static $Shake = GUICtrlCreateTabItem("Shake")
            Local Static $Label_Shake_Question = GUICtrlCreateLabel("Should the plate be shaken?", 10, 40, 145, 20)
            global $Radio_Shake_Yes = GUICtrlCreateRadio("Yes", 170, 37, 70, 20)
;~          GUICtrlSetOnEvent(-1, "radio_Yes")
            global $Radio_Shake_No = GUICtrlCreateRadio("No", 250, 37, 70, 20)
;~          GUICtrlSetOnEvent(-1, "radio_No")
            GUICtrlSetState($Radio_Shake_Yes, $GUI_CHECKED)
            Local Static $Label_Shakespeed = GUICtrlCreateLabel("Shaking speed:", 10, 70, 100, 20)
            Global $Input_Shakespeed = GUICtrlCreateInput("", 100, 65, 70, 20)
            Local Static $MoreSettings = GUICtrlCreateTabItem("More Settings")
            GUICtrlCreateTabItem("")
EndFunc

My script

Link to comment
Share on other sites

you got an error :

Quote

"C:\Applications\AutoIt\Temp6.au3" (110) : ==> Cannot make existing variables static.:
Local Static $Group_Plate_Bottom = GUICtrlCreateGroup("", 5, 175, 230, 130)
Local Static ^ ERROR
 

I really prefer your first script  BTW

Link to comment
Share on other sites

I think in that case would be better concept to use temporary opened new (child) window to allow user to input some options (visually in GUI).

This window will have controls corresponding to menu item from which it has been opened (corresponds to one TabItem here) and buttons OK/Cancel.

So you will not mix dynamic "Options" controls in main GUI and it will be in other new GUI window.

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