Jump to content

Check box


au3scr
 Share

Recommended Posts

hi

I am trying understand how checkbox works, But i have a little problem here.

It show me both msg boxes ,how i can make it show only 1 of them?

here is code I have

#include <GUIConstants.au3>
#include <Process.au3>

Global $var = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 304, 91, 193, 115)
$Name = GUICtrlCreateLabel("Name", 24, 16, 32, 17)
$Password = GUICtrlCreateLabel("Password", 24, 40, 50, 17)
GUICtrlCreateInput("", 88, 16, 121, 21)
GUICtrlCreateInput("", 88, 40, 121, 21)
$IsAdmin = GUICtrlCreateCheckbox("IsAdmin", 24, 64, 97, 17)
$Create = GUICtrlCreateButton("Create", 216, 16, 75, 25, 0)
$exit = GUICtrlCreateButton("exit", 216, 48, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Create
            mkuser ()
        Case $IsAdmin
            admin ()
    EndSwitch
WEnd

Func admin ()
            If $var = 0 Then
                $var = 1
            MsgBox (64,"clicked","Clicked")
            If $var = 1 Then
                $var = 0
            MsgBox (64,"Unclicked","UnClicked")
        EndIf
        EndIf
EndFunc
    
Func mkuser ()
    
IF @OSVersion <> "WIN_XP" THEN
  MsgBox(0,"Error","You have running unknown OS")
ENDIF

$cmd = "net localgroup" & " " & "Administrators" & " pinoccio /add "
;~ _runDOS( "net user pinoccio papacarlo /add")
_runDOS( $cmd)

EndFunc
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <Process.au3>

Global $var = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 304, 91, 193, 115)
$Name = GUICtrlCreateLabel("Name", 24, 16, 32, 17)
$Password = GUICtrlCreateLabel("Password", 24, 40, 50, 17)
GUICtrlCreateInput("", 88, 16, 121, 21)
GUICtrlCreateInput("", 88, 40, 121, 21)
$IsAdmin = GUICtrlCreateCheckbox("IsAdmin", 24, 64, 97, 17)
$Create = GUICtrlCreateButton("Create", 216, 16, 75, 25, 0)
$exit = GUICtrlCreateButton("exit", 216, 48, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exit
            Exit
        Case $Create
            mkuser()
        Case $IsAdmin
            admin()
    EndSwitch
WEnd

Func admin()
    If $var = 0 Then
        $var = 1
        Return MsgBox(64, "clicked", "Clicked")
    EndIf
    If $var = 1 Then
        $var = 0
        Return MsgBox(64, "Unclicked", "UnClicked")
    EndIf
EndFunc   ;==>admin

Func mkuser()

    If @OSVersion <> "WIN_XP"  Then
        MsgBox(0, "Error", "You have running unknown OS")
    EndIf

    $cmd = "net localgroup" & " " & "Administrators" & " pinoccio /add " 
;~ _runDOS( "net user pinoccio papacarlo /add")
    _RunDOS($cmd)

EndFunc   ;==>mkuser

fixed, however you may have future problems doing it this way...

8)

NEWHeader1.png

Link to comment
Share on other sites

A better approach...

#include <GUIConstants.au3>
#include <Process.au3>

Global $var = 0

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 304, 91, 193, 115)
$Name = GUICtrlCreateLabel("Name", 24, 16, 32, 17)
$Password = GUICtrlCreateLabel("Password", 24, 40, 50, 17)
GUICtrlCreateInput("", 88, 16, 121, 21)
GUICtrlCreateInput("", 88, 40, 121, 21)
$IsAdmin = GUICtrlCreateCheckbox("IsAdmin", 24, 64, 97, 17)
$Create = GUICtrlCreateButton("Create", 216, 16, 75, 25, 0)
$exit = GUICtrlCreateButton("exit", 216, 48, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $exit
            Exit
        Case $Create
            mkuser()
        Case $IsAdmin
            ;admin()
            If _IsChecked($IsAdmin) Then MsgBox(64, "clicked", "Clicked")
            ; else the checkbox is not checked "period"!
    EndSwitch
WEnd

Func _IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc

Func admin()
    If $var = 0 Then
        $var = 1
        Return MsgBox(64, "clicked", "Clicked")
    EndIf
    If $var = 1 Then
        $var = 0
        Return MsgBox(64, "Unclicked", "UnClicked")
    EndIf
EndFunc   ;==>admin

Func mkuser()

    If @OSVersion <> "WIN_XP"  Then
        MsgBox(0, "Error", "You have running unknown OS")
    EndIf

    $cmd = "net localgroup" & " " & "Administrators" & " pinoccio /add " 
;~ _runDOS( "net user pinoccio papacarlo /add")
    _RunDOS($cmd)

EndFunc   ;==>mkuser

8)

NEWHeader1.png

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