Jump to content

adding a button to GUI with tabs


sbrady
 Share

Recommended Posts

I copied this code from the help file. It makes a window with 3 tabs on it. I just want to be able to add 1 button that displays a message box so I know it all works. But I cant get it to work. In the middle of all this code is ;sb added so you know what I added that does not work. It tells me:

"Func" statement has no matching "EndFunc".:

Func Example2()

what am I doing wrong that simply adding a button does not work.

---- the code

; big fat GUI

#include

#include

#include

#include

Example()

Func Example()

Local $msg

GUICreate("DAW3 Scripts") ; will create a dialog box that when displayed is centered

GUISetBkColor(0x0CCCCCC)

GUISetFont(9, 300)

GUICtrlCreateTab(10, 10, 370, 370); for all tabs

GUICtrlCreateTabItem("tab0")

GUICtrlCreateLabel("label0", 30, 80, 50, 20)

GUICtrlCreateButton("OK0", 20, 50, 50, 20)

GUICtrlCreateInput("default", 80, 50, 70, 20)

GUICtrlCreateTabItem("tab----1")

GUICtrlCreateLabel("label1", 30, 80, 50, 20)

GUICtrlCreateCombo("", 20, 50, 60, 120)

GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon

GUICtrlCreateButton("OK1", 80, 50, 50, 20)

GUICtrlCreateTabItem("tab2")

GUICtrlSetState(-1, $GUI_SHOW) ; will be display first

GUICtrlCreateLabel("label2", 30, 80, 50, 20)

GUICtrlCreateButton("OK2", 140, 50, 50)

;#cs

;sb added

Example2()

Func Example2()

Local $Button_1, $msg

Opt("GUICoordMode", 2)

$Button_1 = GUICtrlCreateButton("OK2sb", 140, 30, 50,30, $BS_LEFT)

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

;BUTTON 1 clicked

Case $msg = $Button_1

MsgBox(8192, "Test", "you pushed button 1", 5)

;Next

EndSelect

WEnd

EndFunc

;end sb added

;#ce

GUICtrlCreateTabItem("") ; end tabitem definition

;GUICtrlCreateLabel("label3", 20, 130, 50, 20); on main GUI

GUISetState()

; Run the GUI until the dialog is closed

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

EndFunc ;==>Example

Link to comment
Share on other sites

There is no EndFunc for function Example. You can't have a function within a function.

Could you please remove all empty lines from your code and add [autoit][/autoit] tags to make the code more readable? Thanks!

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

Here's the correct code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Example()
Func Example()
    Local $msg
    GUICreate("DAW3 Scripts") ; will create a dialog box that when displayed is centered
    GUISetBkColor(0x0CCCCCC)
    GUISetFont(9, 300)
    GUICtrlCreateTab(10, 10, 370, 370); for all tabs
    GUICtrlCreateTabItem("tab0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)
    GUICtrlCreateTabItem("tab----1")
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
    GUICtrlCreateButton("OK1", 80, 50, 50, 20)

    GUICtrlCreateTabItem("tab2")
    GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)
    GUICtrlCreateTabItem("") ; end tabitem definition
    ;GUICtrlCreateLabel("label3", 20, 130, 50, 20); on main GUI
    GUISetState()

    Local $Button_1, $msg
    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("OK2sb", 140, 30, 50,30, $BS_LEFT)
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
   Case $msg = $Button_1
    MsgBox(8192, "Test", "you pushed button 1", 5)
  EndSelect
    WEnd
EndFunc
Link to comment
Share on other sites

how come this GUI forum does not have the menu like the General Forum where you click on the AutoIT icon, paste in your code looks like you typed it right in..........guess I'll have to do it manual.

I'll try pasting the function I know works outside the Example() function and see if it adds a button to the tab2 pane.

Link to comment
Share on other sites

walter....walter.....walter.......thank you so much for the code. I so appreciate it. You are thee 1st person to so easily and willing gave me the code I needed to accomplish my goal. I cannot thank you enough. I will study this and will learn where I went wrong and write better code faster. Thank you thank you thank you. I am a newbie trying to learn and this will help me a lot.

shawn

Link to comment
Share on other sites

That was quite easy.

I pasted your code to SciTE and when I wanted to make it more readable by running Tidy (Ctrl+t) I got the following error messages:

;### Tidy Error -> func Not closed before "Func" statement.

;### Tidy Error -> "func" cannot be inside any IF/Do/While/For/Case/Func statement.

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 need to place the commands for the buttons in the each tab field.

Once again here's the entire code;

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
Local $Button_1, $msg
Example()
Func Example()
    GUICreate("DAW3 Scripts") ; will create a dialog box that when displayed is centered
    GUISetBkColor(0x0CCCCCC)
    GUISetFont(9, 300)
    GUICtrlCreateTabItem("") ; end tabitem definition
    GUICtrlCreateTab(10, 10, 370, 370); for all tabs
GUICtrlCreateTabItem("tab0")
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)
    $Button_0 = GUICtrlCreateButton("OK_Tab0", 250, 30, 80,30, $BS_LEFT)
    GUICtrlCreateTabItem("tab----1")
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
    GUICtrlCreateButton("OK1", 80, 50, 50, 20)
    $Button_1 = GUICtrlCreateButton("OK_Tab1", 250, 30, 80,30, $BS_LEFT)

    GUICtrlCreateTabItem("tab2")
    GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)
    $Button_2 = GUICtrlCreateButton("OK_Tab2", 250, 30, 80,30, $BS_LEFT)
GUISetState(@SW_SHOW)
Opt("GUICoordMode", 2)
   ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
   Case $msg = $Button_1
    MsgBox(8192, "Test", "you pushed button 1", 5)
  EndSelect
    WEnd
EndFunc
Link to comment
Share on other sites

Hope this helps, it works the way you wanted

#include 
#include 

Local $Button_1, $msg

Example()

Func Example()

GUICreate("DAW3 Scripts") ; will create a dialog box that when displayed is centered
GUISetBkColor(0x0CCCCCC)
GUISetFont(9, 300)

GUICtrlCreateTabItem("") ; end tabitem definition

GUICtrlCreateTab(10, 10, 370, 370); for all tabs

GUICtrlCreateTabItem("tab0")
GUICtrlCreateLabel("label0", 30, 80, 50, 20)
GUICtrlCreateButton("OK0", 20, 50, 50, 20)
GUICtrlCreateInput("default", 80, 50, 70, 20)
$Button_0 = GUICtrlCreateButton("OK_Tab0", 250, 30, 80,30, $BS_LEFT)

GUICtrlCreateTabItem("tab----1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon") ; default Jon
GUICtrlCreateButton("OK1", 80, 50, 50, 20)
$Button_1 = GUICtrlCreateButton("OK_Tab1", 250, 30, 80,30, $BS_LEFT)


GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
GUICtrlCreateButton("OK2", 140, 50, 50)
$Button_2 = GUICtrlCreateButton("OK_Tab2", 250, 30, 80,30, $BS_LEFT)

GUISetState(@SW_SHOW)
Opt("GUICoordMode", 2)

; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop

Case $msg = $Button_0
MsgBox(8192, "Test", "you pushed " & GUICtrlRead($msg), 5)

Case $msg = $Button_1
MsgBox(8192, "Test", "you pushed " & GUICtrlRead($msg), 5)

Case $msg = $Button_2
MsgBox(8192, "Test", "you pushed " & GUICtrlRead($msg), 5)
EndSelect
WEnd
EndFunc
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...