Jump to content

My buttons, they do nothing..


Recommended Posts

Well, i've been staring at this script for four days on and off.....The first part works as it should calling my second form.....but the second form just sits there, all buttons do nothing, even the close button. I thought i was over looking something, so i re-wrote the whole thing i another script to just test the form, same result. WHAT am i missing :[

Func first()
    $frmfirst = GUICreate("Post-Installer", 199, 160, -1, -1)

    $dsk = GUICtrlCreateButton("DESKTOP", 8, 32, 177, 49, 0)
    GUICtrlSetOnEvent(-1, "dsk")
    
    $lap = GUICtrlCreateButton("LAPTOP", 8, 88, 177, 57, 0)
    GUICtrlSetOnEvent(-1, "lap")
    
    $lbl1 = GUICtrlCreateLabel("Please Choose Workstation Type", 16, 8, 162, 17)
    
    GUISetState()
    
    While 1
        $rt1 = GUIGetMsg()
        Select
            Case $rt1 = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
EndFunc 

Func dsk()
    $choice = 1
    GUISetState(@SW_HIDE, $frmfirst)
    second()
EndFunc

func lap()
    $choice = 2
    GUISetState(@SW_HIDE, $frmfirst)
    second()    
EndFunc

Func second()
    $frmsecond = GUICreate('Pre-Installer Options',400,150)
    GUISetOnEvent($GUI_EVENT_CLOSE, "x")
    
    $CBav = GUICtrlCreateCheckbox("FIRST PROGRAM",10,20,150,20) 
    GUICtrlSetState($CBav,$GUI_CHECKED)
    
    $CBsee = GUICtrlCreateCheckbox("SECOND PROGRAM",10,40,150,20)
    GUICtrlSetState($CBsee,$GUI_CHECKED)
    
    $CBsee2 = GUICtrlCreateCheckbox("THIRD PROGRAM (Laptops ONLY!)",10,60,250,20)
    
    $BTbck = GUICtrlCreateButton("< BACK", 256, 111, 57, 25, 0)
    GUICtrlSetOnEvent(-1, "back")
    
    $BTnxt = GUICtrlCreateButton("NEXT >", 325, 111, 57, 25, 0)
    GUICtrlSetOnEvent(-1, "process")
    
    GUISetState()
    
    
    if $choice = 1 Then
        GUICtrlSetState($CBsee2,$GUI_DISABLE)
    Else
        GUICtrlSetState($CBsee2,$GUI_ENABLE)
        GUICtrlSetState($CBsee2,$GUI_CHECKED)
    EndIf
    $rt2 = GUIGetMsg()
    If $rt2 = -3 Then
        Exit
    EndIf
    If GUICtrlRead($CBav) = 1 Then 
        $av = 1
    Else
        $av = 0
    EndIf
    if GUICtrlRead($CBsee) = 1 Then
        $see = 1
    Else
        $see = 0
    EndIf
    if GUICtrlRead($CBsee2) = 1 Then
        $see2 = 1
    Else
        $see2 = 0
    EndIf
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
        sleep(1000)
    WEnd
    
EndFunc

The Func "process" just runs the installs with runwaits.... Why oh why do these not work :/

Link to comment
Share on other sites

Hi there,

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <Timers.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $frmfirst, $choice

    $frmfirst = GUICreate("Post-Installer", 199, 160, -1, -1)
    $dsk = GUICtrlCreateButton("DESKTOP", 8, 32, 177, 49, 0)
    GUICtrlSetOnEvent(-1, "dsk")
    $lap = GUICtrlCreateButton("LAPTOP", 8, 88, 177, 57, 0)
    GUICtrlSetOnEvent(-1, "lap")
    $lbl1 = GUICtrlCreateLabel("Please Choose Workstation Type", 16, 8, 162, 17)
    GUISetState()

first()


Func first()
    While 1
        $rt1 = GUIGetMsg()
        Select
            Case $rt1 = $GUI_EVENT_CLOSE
                ExitLoop
            case $rt1 = $dsk
                dsk()
            case $rt1 = $lap
                lap()
        EndSelect
        Sleep(100)
    WEnd
EndFunc

Func dsk()
    $choice = 1
    GUISetState(@SW_HIDE, $frmfirst)
    second()
EndFunc

func lap()
    $choice = 2
    GUISetState(@SW_HIDE, $frmfirst)
    second()
EndFunc

Func second()
    $frmsecond = GUICreate('Pre-Installer Options',400,150)
    GUISetOnEvent($GUI_EVENT_CLOSE, "x")

    $CBav = GUICtrlCreateCheckbox("FIRST PROGRAM",10,20,150,20)
    GUICtrlSetState($CBav,$GUI_CHECKED)

    $CBsee = GUICtrlCreateCheckbox("SECOND PROGRAM",10,40,150,20)
    GUICtrlSetState($CBsee,$GUI_CHECKED)

    $CBsee2 = GUICtrlCreateCheckbox("THIRD PROGRAM (Laptops ONLY!)",10,60,250,20)

    $BTbck = GUICtrlCreateButton("< BACK", 256, 111, 57, 25, 0)
    GUICtrlSetOnEvent(-1, "back")

    $BTnxt = GUICtrlCreateButton("NEXT >", 325, 111, 57, 25, 0)
    GUICtrlSetOnEvent(-1, "process")

    GUISetState()


    if $choice = 1 Then
        GUICtrlSetState($CBsee2,$GUI_DISABLE)
    Else
        GUICtrlSetState($CBsee2,$GUI_ENABLE)
        GUICtrlSetState($CBsee2,$GUI_CHECKED)
    EndIf
    $rt2 = GUIGetMsg()
    If $rt2 = -3 Then
        Exit
    EndIf
    If GUICtrlRead($CBav) = 1 Then
        $av = 1
    Else
        $av = 0
    EndIf
    if GUICtrlRead($CBsee) = 1 Then
        $see = 1
    Else
        $see = 0
    EndIf
    if GUICtrlRead($CBsee2) = 1 Then
        $see2 = 1
    Else
        $see2 = 0
    EndIf
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
        sleep(1000)
    WEnd

EndFunc

func x()

EndFunc

func back()

EndFunc

func process()

endfunc

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

  • Moderators

drx,

WHAT am i missing

The fact that you cannot mix OnEvent and MessageLoop modes in the same script*. :ph34r:

Unless you have an Opt("GUIOnEventMode", 1) line somewhere else in your script, your GUICtrlSetOnEvent lines are ignored. And if you do have that line, then GUIGetMsg will always return 0.

Rewrite your script to use one or other of the modes and thing will begin to work. ;)

If you let me know which mode you wish to use, i can give you a quick starter for 10. :huh2:

M23

* Actually you can mix them in the same script, but there is usually little need to do so and you need to take extreme care when you do. :alien:

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

drx,

The fact that you cannot mix OnEvent and MessageLoop modes in the same script*. :)

Unless you have an Opt("GUIOnEventMode", 1) line somewhere else in your script, your GUICtrlSetOnEvent lines are ignored. And if you do have that line, then GUIGetMsg will always return 0.

Rewrite your script to use one or other of the modes and thing will begin to work. :alien:

If you let me know which mode you wish to use, i can give you a quick starter for 10. :huh2:

M23

* Actually you can mix them in the same script, but there is usually little need to do so and you need to take extreme care when you do. :ph34r:

Melba,

They would be amazed and shocked if they hit F1 over a command in Scite! ;)

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

  • Moderators

drx,

Here is your script rewritten in the 2 modes so you can see the difference.

First OnEvent mode:

; OnEvent mode

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $frmfirst, $frmsecond, $choice = 0, $CBav, $CBsee, $CBsee2

first()

While 1
    Sleep(10)
WEnd

Func first()
    $frmfirst = GUICreate("Post-Installer", 199, 160, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")

    $dsk = GUICtrlCreateButton("DESKTOP", 8, 32, 177, 49, 0)
    GUICtrlSetOnEvent(-1, "dsk")

    $lap = GUICtrlCreateButton("LAPTOP", 8, 88, 177, 57, 0)
    GUICtrlSetOnEvent(-1, "lap")

    $lbl1 = GUICtrlCreateLabel("Please Choose Workstation Type", 16, 8, 162, 17)

    GUISetState()

EndFunc

Func dsk()
    $choice = 1
    second()
EndFunc

func lap()
    $choice = 2
    second()
EndFunc

Func second()

    GUISetState(@SW_HIDE, $frmfirst)

    $frmsecond = GUICreate('Pre-Installer Options',400,150)
    GUISetOnEvent($GUI_EVENT_CLOSE, "back")

    $CBav = GUICtrlCreateCheckbox("FIRST PROGRAM",10,20,150,20)
    GUICtrlSetState($CBav,$GUI_CHECKED)

    $CBsee = GUICtrlCreateCheckbox("SECOND PROGRAM",10,40,150,20)
    GUICtrlSetState($CBsee,$GUI_CHECKED)

    $CBsee2 = GUICtrlCreateCheckbox("THIRD PROGRAM (Laptops ONLY!)",10,60,250,20)
    If $choice = 1 Then
        GUICtrlSetState($CBsee2,$GUI_DISABLE)
    Else
        GUICtrlSetState($CBsee2,$GUI_ENABLE)
        GUICtrlSetState($CBsee2,$GUI_CHECKED)
    EndIf

    $BTbck = GUICtrlCreateButton("< BACK", 256, 111, 57, 25, 0)
    GUICtrlSetOnEvent(-1, "back")

    $BTnxt = GUICtrlCreateButton("NEXT >", 325, 111, 57, 25, 0)
    GUICtrlSetOnEvent(-1, "process")

    GUISetState()

EndFunc

Func back()
    GUISetState(@SW_SHOW, $frmfirst)
    GUIDelete($frmsecond)
    $choice = 0
EndFunc

Func process()

    Local $av = 0, $see = 0, $see2 = 0

    If GUICtrlRead($CBav) = 1 Then
        $av = 1
    EndIf
    If GUICtrlRead($CBsee) = 1 Then
        $see = 1
    EndIf
    If GUICtrlRead($CBsee2) = 1 Then
        $see2 = 1
    EndIf

    MsgBox(0, "State", "$av:" & @TAB & $av & @CRLF & "$see:" & @TAB & $see & @CRLF & "$see2:" & @TAB & $see2)

    Exit

EndFunc

Func On_Exit()
    Exit
EndFunc

And now MessageLoop mode:

; MessageLoop mode

#include <GUIConstantsEx.au3>

Global $frmfirst

first()

Func first()
    $frmfirst = GUICreate("Post-Installer", 199, 160, -1, -1)

    $dsk = GUICtrlCreateButton("DESKTOP", 8, 32, 177, 49, 0)

    $lap = GUICtrlCreateButton("LAPTOP", 8, 88, 177, 57, 0)

    $lbl1 = GUICtrlCreateLabel("Please Choose Workstation Type", 16, 8, 162, 17)

    GUISetState()

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $dsk
                second(1)
            Case $lap
                second(2)
        EndSwitch

    WEnd

EndFunc

Func second($choice)

    GUISetState(@SW_HIDE, $frmfirst)

    $frmsecond = GUICreate('Pre-Installer Options',400,150)

    $CBav = GUICtrlCreateCheckbox("FIRST PROGRAM",10,20,150,20)
    GUICtrlSetState($CBav,$GUI_CHECKED)

    $CBsee = GUICtrlCreateCheckbox("SECOND PROGRAM",10,40,150,20)
    GUICtrlSetState($CBsee,$GUI_CHECKED)

    $CBsee2 = GUICtrlCreateCheckbox("THIRD PROGRAM (Laptops ONLY!)",10,60,250,20)
    If $choice = 1 Then
        GUICtrlSetState($CBsee2,$GUI_DISABLE)
    Else
        GUICtrlSetState($CBsee2,$GUI_ENABLE)
        GUICtrlSetState($CBsee2,$GUI_CHECKED)
    EndIf

    $BTbck = GUICtrlCreateButton("< BACK", 256, 111, 57, 25, 0)

    $BTnxt = GUICtrlCreateButton("NEXT >", 325, 111, 57, 25, 0)

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $BTnxt
                Local $av = 0, $see = 0, $see2 = 0

                If GUICtrlRead($CBav) = 1 Then
                    $av = 1
                EndIf
                If GUICtrlRead($CBsee) = 1 Then
                    $see = 1
                EndIf
                If GUICtrlRead($CBsee2) = 1 Then
                    $see2 = 1
                EndIf

                MsgBox(0, "State", "$av:" & @TAB & $av & @CRLF & "$see:" & @TAB & $see & @CRLF & "$see2:" & @TAB & $see2)

                Exit
            Case $GUI_EVENT_CLOSE, $BTbck
                GUISetState(@SW_SHOW, $frmfirst)
                GUIDelete($frmsecond)
                ExitLoop


        EndSwitch
    WEnd

EndFunc

These 2 scripts are functionally identical, but as you can see they are very different in coding terms.

Please study them carefully in conjunction with the <GUI Reference> pages in the Help file. Then if you have any questions, please ask and I will try to explain. :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you Melba23, you steered me into the right direction. I had the mindset that the button variable would not transfer data between functions for some reason :]

After re-writing my code using your example, I figured out my stonewall :huh2:

Now time to debug a few little quarks....

Thanks again!

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