Jump to content

Recommended Posts

Posted

Hey, First, sry for my bad english.

I made an script but it doesent work. i dont know why. can someone help me^^? I started learning autoit yesterday so do not wonder if the script is trash. :D

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AutoIT Textscript ", 290, 167, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Button1", 8, 8, 129, 17)
$Checkbox1 = GUICtrlCreateCheckbox("Button2", 8, 32, 129, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Button3", 8, 56, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Button4", 8, 80, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Button5", 8, 104, 97, 17)
$Button1 = GUICtrlCreateButton("Scan", 176, 32, 107, 65, $WS_GROUP)
$Button2 = GUICtrlCreateButton("?", 144, 8, 19, 17, $WS_GROUP)
$Button3 = GUICtrlCreateButton("?", 144, 33, 19, 17, $WS_GROUP)
$Button4 = GUICtrlCreateButton("?", 144, 56, 19, 17, $WS_GROUP)
$Button5 = GUICtrlCreateButton("?", 144, 80, 19, 17, $WS_GROUP)
$Button6 = GUICtrlCreateButton("?", 144, 104, 19, 17, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Testscript", 184, 8, 90, 17)
$Label2 = GUICtrlCreateLabel("AutoIT lernen:)", 184, 104, 89, 17)
$Progress1 = GUICtrlCreateProgress(8, 128, 274, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetState($button1,$GUI_DISABLE)
GUISetState()

While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button2
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button3
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button4
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button5
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button6
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         EndSwitch

    $aMsg = GUIGetMsg(1)
    $read = GUICtrlRead($checkbox1)
    Switch $aMsg

   If $aMsg = $GUI_EVENT_CLOSE Then ExitLoop
   If $aMsg = $checkbox1 And $read = $GUI_CHECKED Then
            GUICtrlSetState($button1,$GUI_ENABLE)
   ElseIf $aMsg = $checkbox1 And $read = $GUI_UNCHECKED Then
            GUICtrlSetState($button1,$GUI_DISABLE)
   EndIf

      Endswitch



WEnd
Posted (edited)

You got a number of problems. While in SciTE and the script open press CTRL+F5 (the control key and the F5 key at the same time). This will run a syntax production check and show you what is wrong with your script.

for example you have a switch inside a switch without a endswitch.

Edited by DarthCookieMonster
Posted

I'm trying to fix your script and I have a question - Why are you using check boxes to enable or disable a button on the same screen?

 

I want that you only can click Button1 if you checked checkbox1

Posted (edited)

In the long run do you intend to have the check box and the button on the same screen?

 

I want it like this 

#include <GUIConstantsEx.au3>
GUICreate("")
$check = GUICtrlCreateCheckbox("Enable/Disable Buttons", 10, 10, 140, 20)
$button = GUICtrlCreateButton("Button",10,50)
GUICtrlSetState($button,$GUI_DISABLE)
GUISetState()



While 1
    $msg = GUIGetMsg()
    $read = GUICtrlRead($check)
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $check And $read = $GUI_CHECKED Then
        GUICtrlSetState($button,$GUI_ENABLE)
    ElseIf $msg = $check And $read = $GUI_UNCHECKED Then
        GUICtrlSetState($button,$GUI_DISABLE)
    EndIf
WEnd

But with this

Case $Button2
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button3
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button4
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button5
            MsgBox($MB_ICONINFORMATION,"Info","Text")
         Case $Button6
            MsgBox($MB_ICONINFORMATION,"Info","Text")
Edited by Chinx2013
Posted

Try this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
DIM $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5
DIM $Button1, $Button2, $Button3, $Button4, $Button5
$Form1 = GUICreate("AutoIT Textscript ", 290, 167, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Button1", 8, 8, 129, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Button2", 8, 32, 129, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Button3", 8, 56, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Button4", 8, 80, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Button5", 8, 104, 97, 17)
$Button1 = GUICtrlCreateButton("1 - Scan", 176, 32, 107, 65, $WS_GROUP)
$Button2 = GUICtrlCreateButton("2", 144, 8, 19, 17, $WS_GROUP)
$Button3 = GUICtrlCreateButton("3", 144, 33, 19, 17, $WS_GROUP)
$Button4 = GUICtrlCreateButton("4", 144, 56, 19, 17, $WS_GROUP)
$Button5 = GUICtrlCreateButton("5", 144, 80, 19, 17, $WS_GROUP)
$Button6 = GUICtrlCreateButton("6", 144, 104, 19, 17, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Testscript", 184, 8, 90, 17)
$Label2 = GUICtrlCreateLabel("AutoIT lernen:)", 184, 104, 89, 17)
$Progress1 = GUICtrlCreateProgress(8, 128, 274, 33)
GUISetState(@SW_SHOW)
_chkGetState()
#EndRegion ### END Koda GUI section ###

GUICtrlSetState($button1,$GUI_DISABLE)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            _btnSET($Button1,$Checkbox1)
        Case $Checkbox2
            _btnSET($Button2,$Checkbox2)
        Case $Checkbox3
            _btnSET($Button3,$Checkbox3)
        Case $Checkbox4
            _btnSET($Button4,$Checkbox4)
        Case $Checkbox5
            _btnSET($Button5,$Checkbox5)
        Case $Button1
            MsgBox($MB_ICONINFORMATION,"Info","Button 1 pushed")
         Case $Button2
            MsgBox($MB_ICONINFORMATION,"Info","Button 2 pushed")
         Case $Button3
            MsgBox($MB_ICONINFORMATION,"Info","Button 3 pushed")
         Case $Button4
            MsgBox($MB_ICONINFORMATION,"Info","Button 4 pushed")
         Case $Button5
            MsgBox($MB_ICONINFORMATION,"Info","Button 5 pushed")
         Case $Button6
            MsgBox($MB_ICONINFORMATION,"Info","Button 6 pushed. This button has no checkbox to disable it!")
         EndSwitch
WEnd ;moved up here.

Func _btnSET($btn, $ckb)
    $read = GUICtrlRead($ckb)
    If $read = 1 then
        GUICtrlSetState($btn,$GUI_ENABLE)
    EndIf
    If $read = 4 then
        GUICtrlSetState($btn,$GUI_DISABLE)
    EndIf
EndFunc

Func _chkGetState()
    $r1 = GUICtrlRead($Checkbox1)
    If $r1 = 4 then GUICtrlSetState($button1,$GUI_DISABLE)
    $r2 = GUICtrlRead($Checkbox1)
    If $r2 = 4 then GUICtrlSetState($button2,$GUI_DISABLE)
    $r3 = GUICtrlRead($Checkbox1)
    If $r3 = 4 then GUICtrlSetState($button3,$GUI_DISABLE)
    $r4 = GUICtrlRead($Checkbox1)
    If $r4 = 4 then GUICtrlSetState($button4,$GUI_DISABLE)
    $r5 = GUICtrlRead($Checkbox5)
    If $r5 = 4 then GUICtrlSetState($button5,$GUI_DISABLE)
EndFunc
Posted

 

Try this:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
DIM $Checkbox1, $Checkbox2, $Checkbox3, $Checkbox4, $Checkbox5
DIM $Button1, $Button2, $Button3, $Button4, $Button5
$Form1 = GUICreate("AutoIT Textscript ", 290, 167, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Button1", 8, 8, 129, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Button2", 8, 32, 129, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Button3", 8, 56, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("Button4", 8, 80, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("Button5", 8, 104, 97, 17)
$Button1 = GUICtrlCreateButton("1 - Scan", 176, 32, 107, 65, $WS_GROUP)
$Button2 = GUICtrlCreateButton("2", 144, 8, 19, 17, $WS_GROUP)
$Button3 = GUICtrlCreateButton("3", 144, 33, 19, 17, $WS_GROUP)
$Button4 = GUICtrlCreateButton("4", 144, 56, 19, 17, $WS_GROUP)
$Button5 = GUICtrlCreateButton("5", 144, 80, 19, 17, $WS_GROUP)
$Button6 = GUICtrlCreateButton("6", 144, 104, 19, 17, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Testscript", 184, 8, 90, 17)
$Label2 = GUICtrlCreateLabel("AutoIT lernen:)", 184, 104, 89, 17)
$Progress1 = GUICtrlCreateProgress(8, 128, 274, 33)
GUISetState(@SW_SHOW)
_chkGetState()
#EndRegion ### END Koda GUI section ###

GUICtrlSetState($button1,$GUI_DISABLE)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Checkbox1
            _btnSET($Button1,$Checkbox1)
        Case $Checkbox2
            _btnSET($Button2,$Checkbox2)
        Case $Checkbox3
            _btnSET($Button3,$Checkbox3)
        Case $Checkbox4
            _btnSET($Button4,$Checkbox4)
        Case $Checkbox5
            _btnSET($Button5,$Checkbox5)
        Case $Button1
            MsgBox($MB_ICONINFORMATION,"Info","Button 1 pushed")
         Case $Button2
            MsgBox($MB_ICONINFORMATION,"Info","Button 2 pushed")
         Case $Button3
            MsgBox($MB_ICONINFORMATION,"Info","Button 3 pushed")
         Case $Button4
            MsgBox($MB_ICONINFORMATION,"Info","Button 4 pushed")
         Case $Button5
            MsgBox($MB_ICONINFORMATION,"Info","Button 5 pushed")
         Case $Button6
            MsgBox($MB_ICONINFORMATION,"Info","Button 6 pushed. This button has no checkbox to disable it!")
         EndSwitch
WEnd ;moved up here.

Func _btnSET($btn, $ckb)
    $read = GUICtrlRead($ckb)
    If $read = 1 then
        GUICtrlSetState($btn,$GUI_ENABLE)
    EndIf
    If $read = 4 then
        GUICtrlSetState($btn,$GUI_DISABLE)
    EndIf
EndFunc

Func _chkGetState()
    $r1 = GUICtrlRead($Checkbox1)
    If $r1 = 4 then GUICtrlSetState($button1,$GUI_DISABLE)
    $r2 = GUICtrlRead($Checkbox1)
    If $r2 = 4 then GUICtrlSetState($button2,$GUI_DISABLE)
    $r3 = GUICtrlRead($Checkbox1)
    If $r3 = 4 then GUICtrlSetState($button3,$GUI_DISABLE)
    $r4 = GUICtrlRead($Checkbox1)
    If $r4 = 4 then GUICtrlSetState($button4,$GUI_DISABLE)
    $r5 = GUICtrlRead($Checkbox5)
    If $r5 = 4 then GUICtrlSetState($button5,$GUI_DISABLE)
EndFunc

Thank you.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...