Jump to content

Opt("GUIOnEventMode", 0)


 Share

Recommended Posts

Hi ya.

I have a GUI that has buttons and check boxes. When I started it only had check boxes and then when I added buttons and this bit of code "Opt("GUIOnEventMode", 1)" to make the buttons run functions, it seems to stop the check boxes from working.

What am I doing wrong?

Cheers

Baz.

Edited by Baz
Link to comment
Share on other sites

  • Moderators

Hi ya.

I have a GUI that has buttons and check boxes. When I started it only had check boxes and then when I added buttons and this bit of code "Opt("GUIOnEventMode", 0)" to make the buttons run functions, it seems to stop the check boxes from working.

What am I doing wrong?

Cheers

Baz.

Well the first thing your doing wrong, is you didn't post your code! (Also the last thing your doing wrong if you look at this in retrospect)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Well the first thing your doing wrong, is you didn't post your code! (Also the last thing your doing wrong if you look at this in retrospect)

Code:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

$lpt1 = 888 ; hex. is 378 so dec. is 888

$lpt2 = 632 ; hex. is 278 so dec. is 632

$BasePortAddr = $lpt1

Dim $lptData, $d1=0, $d2=0, $d3=0, $d4=0, $d5=0, $d6=0, $d7=0, $d8=0

$Form3 = GUICreate("BazMan Parallel Port Control", 412, 297, 302, 218, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))

$lptd1 = GUICtrlCreateCheckbox("LED1", 10, 40, 50)

$lptd2 = GUICtrlCreateCheckbox("LED2", 10, 60, 50)

$lptd3 = GUICtrlCreateCheckbox("LED3", 10, 80, 50)

$lptd4 = GUICtrlCreateCheckbox("LED4", 10, 100, 50)

$lptd5 = GUICtrlCreateCheckbox("LED5", 10, 120, 50)

$lptd6 = GUICtrlCreateCheckbox("LED6", 10, 140, 50)

$lptd7 = GUICtrlCreateCheckbox("LED7", 10, 160, 50)

$lptd8 = GUICtrlCreateCheckbox("LED8", 10, 180, 50)

$Input1 = GUICtrlCreateInput("", 200, 40, 161, 200, BitOR($ES_MULTILINE,$ES_WANTRETURN))

$Button11 = GUICtrlCreateButton("ON", 90, 40, 65, 25, 0)

$Button12 = GUICtrlCreateButton("OFF", 90, 72, 65, 25, 0)

$Button13 = GUICtrlCreateButton("WAIT", 90, 104, 65, 25, 0)

GUICtrlSetOnEvent (-1, "insrtwait")

$Button14 = GUICtrlCreateButton("LOOP", 90, 136, 65, 25, 0)

$Button15 = GUICtrlCreateButton("START", 90, 168, 65, 25, 0)

$Button16 = GUICtrlCreateButton("STOP", 90, 200, 65, 25, 0)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

DllCall("inpout32.dll", "short", "Out32", "short", $BasePortAddr, "int", 00000000)

Exit

Case $msg = $lptd1

If BitAND(GUICtrlRead($lptd1), $GUI_CHECKED) Then $d1=1

If BitAND(GUICtrlRead($lptd1), $GUI_UNCHECKED) Then $d1=0

call("led")

Case $msg = $lptd2

If BitAND(GUICtrlRead($lptd2), $GUI_CHECKED) Then $d2=2

If BitAND(GUICtrlRead($lptd2), $GUI_UNCHECKED) Then $d2=0

call("led")

Case $msg = $lptd3

If BitAND(GUICtrlRead($lptd3), $GUI_CHECKED) Then $d3=4

If BitAND(GUICtrlRead($lptd3), $GUI_UNCHECKED) Then $d3=0

call("led")

Case $msg = $lptd4

If BitAND(GUICtrlRead($lptd4), $GUI_CHECKED) Then $d4=8

If BitAND(GUICtrlRead($lptd4), $GUI_UNCHECKED) Then $d4=0

call("led")

Case $msg = $lptd5

If BitAND(GUICtrlRead($lptd5), $GUI_CHECKED) Then $d5=16

If BitAND(GUICtrlRead($lptd5), $GUI_UNCHECKED) Then $d5=0

call("led")

Case $msg = $lptd6

If BitAND(GUICtrlRead($lptd6), $GUI_CHECKED) Then $d6=32

If BitAND(GUICtrlRead($lptd6), $GUI_UNCHECKED) Then $d6=0

call("led")

Case $msg = $lptd7

If BitAND(GUICtrlRead($lptd7), $GUI_CHECKED) Then $d7=64

If BitAND(GUICtrlRead($lptd7), $GUI_UNCHECKED) Then $d7=0

call("led")

Case $msg = $lptd8

If BitAND(GUICtrlRead($lptd8), $GUI_CHECKED) Then $d8=128

If BitAND(GUICtrlRead($lptd8), $GUI_UNCHECKED) Then $d8=0

call("led")

EndSelect

WEnd

Func led()

$lptData=$d1+$d2+$d3+$d4+$d5+$d6+$d7+$d8

DllCall("inpout32.dll", "short", "Out32", "short", $BasePortAddr, "int", $lptData)

EndFunc

Func insrtwait()

GUICtrlSetData($Input1,"Wait",1)

EndFunc

Link to comment
Share on other sites

I've only scrolled through it so far, but I already see an issue. You're trying to use GUIOnEventMode and GUIGetMsg at the same time. They don't go together - it's either one or the other.

Looks like you don't really need oneventmode - you're not using it enough to make a difference. Just get rid of the events, and use the msg loop.

Oh and next time, use code tags.

Link to comment
Share on other sites

  • Moderators

#include <GUIConstants.au3>
$lpt1 = 888; hex. is 378 so dec. is 888
$lpt2 = 632; hex. is 278 so dec. is 632
$BasePortAddr = $lpt1
Dim $lptData, $cCount = 1, $lptd[9], $d[9]
$Form3 = GUICreate("BazMan Parallel Port Control", 412, 297, 302, 218, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
For $i = 1 To 8
    $lptd[$i] = GUICtrlCreateCheckbox("LED" & $i, 10, 40 + ($i - 1) * 20, 50)
    $d[$i] = 0
Next

$Input1 = GUICtrlCreateInput("", 200, 40, 161, 200, BitOR($ES_MULTILINE,$ES_WANTRETURN))
$Button11 = GUICtrlCreateButton("ON", 90, 40, 65, 25, 0)
$Button12 = GUICtrlCreateButton("OFF", 90, 72, 65, 25, 0)
$Button13 = GUICtrlCreateButton("WAIT", 90, 104, 65, 25, 0)
$Button14 = GUICtrlCreateButton("LOOP", 90, 136, 65, 25, 0)
$Button15 = GUICtrlCreateButton("START", 90, 168, 65, 25, 0)
$Button16 = GUICtrlCreateButton("STOP", 90, 200, 65, 25, 0)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            DllCall("inpout32.dll", "short", "Out32", "short", $BasePortAddr, "int", 00000000)
            Exit
        Case $msg = $Button13
            insrtwait()
    EndSelect
    For $x = 1 To 8
        Select
        Case $msg = $lptd[$x]
            If $x == 1 Then
                If BitAND(GUICtrlRead($lptd[$x]), $GUI_CHECKED) Then $d[$x] = 1
                If BitAND(GUICtrlRead($lptd[$x]), $GUI_UNCHECKED) Then $d[$x] = 0
            Else
                $cCount = $cCount * 2
                If BitAND(GUICtrlRead($lptd[$x]), $GUI_CHECKED) Then $d[$x] = $cCount
                If BitAND(GUICtrlRead($lptd[$x]), $GUI_UNCHECKED) Then $d[$x] = 0
            EndIf
            If $x == 8 Then $cCount = 1
        ;MsgBox(0, 'Testing', $lptd[$x])
            led()
        EndSelect
    Next
WEnd

Func led()
    For $i = 1 To 8
        $lptData = $lptData + $d[$i]
    Next
    DllCall("inpout32.dll", "short", "Out32", "short", $BasePortAddr, "int", $lptData)
    $lptData = ''
EndFunc

Func insrtwait()
    GUICtrlSetData($Input1, "Wait", 1)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Did this work for you?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Did this work for you?

Sorry for the delay in replying, sort of but not all outputs worked. I have changed the code as recommended to use Case $MSG. I am still learning as I have not tried to do anything like this before. I am use to batch files!

Anyway this is what I have at the moment.

Thanks for the help.

#include <GUIConstants.au3>
$lpt1 = 888; hex. is 378 so dec. is 888
$lpt2 = 632; hex. is 278 so dec. is 632
$BasePortAddr = $lpt1
Dim $lptData, $d1=0, $d2=0, $d3=0, $d4=0, $d5=0, $d6=0, $d7=0, $d8=0
$Form3 = GUICreate("BazMan Parallel Port Control", 412, 297, 302, 218, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
$lptd1 = GUICtrlCreateCheckbox("LED1", 10, 40, 50)
$lptd2 = GUICtrlCreateCheckbox("LED2", 10, 60, 50)
$lptd3 = GUICtrlCreateCheckbox("LED3", 10, 80, 50)
$lptd4 = GUICtrlCreateCheckbox("LED4", 10, 100, 50)
$lptd5 = GUICtrlCreateCheckbox("LED5", 10, 120, 50)
$lptd6 = GUICtrlCreateCheckbox("LED6", 10, 140, 50)
$lptd7 = GUICtrlCreateCheckbox("LED7", 10, 160, 50)
$lptd8 = GUICtrlCreateCheckbox("LED8", 10, 180, 50)
$Input1 = GUICtrlCreateInput("", 200, 40, 161, 200, BitOR($ES_MULTILINE,$ES_WANTRETURN))
$Button11 = GUICtrlCreateButton("ON", 90, 40, 65, 25, 0)
$Button12 = GUICtrlCreateButton("OFF", 90, 72, 65, 25, 0)
$Button13 = GUICtrlCreateButton("WAIT", 90, 104, 65, 25, 0)
$Button14 = GUICtrlCreateButton("LOOP", 90, 136, 65, 25, 0)
$Button15 = GUICtrlCreateButton("START", 90, 168, 65, 25, 0)
$Button16 = GUICtrlCreateButton("STOP", 90, 200, 65, 25, 0)
GUISetState(@SW_SHOW)
While 1
   $msg = GUIGetMsg()
   Select
   Case $msg = $GUI_EVENT_CLOSE
        DllCall("inpout32.dll", "short", "Out32", "short", $BasePortAddr, "int", 00000000)
         Exit 
     Case $msg = $button11
        GUICtrlSetData($Input1,"Wait",1)
     Case $msg = $button12
        GUICtrlSetData($Input1,"Wait",1)
     Case $msg = $button13
        GUICtrlSetData($Input1,"Wait",1)
     Case $msg = $button14
        GUICtrlSetData($Input1,"Wait",1)
     Case $msg = $button15
        GUICtrlSetData($Input1,"Wait",1)     
     Case $msg = $button16
        GUICtrlSetData($Input1,"Wait",1)
     Case $msg = $lptd1
        If BitAND(GUICtrlRead($lptd1), $GUI_CHECKED) Then $d1=1
        If BitAND(GUICtrlRead($lptd1), $GUI_UNCHECKED) Then $d1=0
        call("led") 
     Case $msg = $lptd2
        If BitAND(GUICtrlRead($lptd2), $GUI_CHECKED) Then $d2=2
        If BitAND(GUICtrlRead($lptd2), $GUI_UNCHECKED) Then $d2=0
        call("led")
     Case $msg = $lptd3
        If BitAND(GUICtrlRead($lptd3), $GUI_CHECKED) Then $d3=4
        If BitAND(GUICtrlRead($lptd3), $GUI_UNCHECKED) Then $d3=0
        call("led")
     Case $msg = $lptd4
        If BitAND(GUICtrlRead($lptd4), $GUI_CHECKED) Then $d4=8
        If BitAND(GUICtrlRead($lptd4), $GUI_UNCHECKED) Then $d4=0
        call("led")
     Case $msg = $lptd5
        If BitAND(GUICtrlRead($lptd5), $GUI_CHECKED) Then $d5=16
        If BitAND(GUICtrlRead($lptd5), $GUI_UNCHECKED) Then $d5=0
        call("led") 
     Case $msg = $lptd6
        If BitAND(GUICtrlRead($lptd6), $GUI_CHECKED) Then $d6=32
        If BitAND(GUICtrlRead($lptd6), $GUI_UNCHECKED) Then $d6=0
        call("led")
     Case $msg = $lptd7
        If BitAND(GUICtrlRead($lptd7), $GUI_CHECKED) Then $d7=64
        If BitAND(GUICtrlRead($lptd7), $GUI_UNCHECKED) Then $d7=0
        call("led")
     Case $msg = $lptd8
        If BitAND(GUICtrlRead($lptd8), $GUI_CHECKED) Then $d8=128
        If BitAND(GUICtrlRead($lptd8), $GUI_UNCHECKED) Then $d8=0
        call("led")
   EndSelect
WEnd
Func led()
    $lptData=$d1+$d2+$d3+$d4+$d5+$d6+$d7+$d8
    DllCall("inpout32.dll", "short", "Out32", "short", $BasePortAddr, "int", $lptData)
EndFunc
Link to comment
Share on other sites

just wanted to know one thing...out of the two options, namely On Event Mode and Message Loop Mode, which one is efficient?

At first glance, the idea I get is Message Loop mode constantly polls the GUI which means, may be, more intensive.

If I have option to go for either, which should I chhose?

I believe we should all pay our tax with a smile. I tried - but they wanted cash!

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