au3scr Posted January 19, 2008 Posted January 19, 2008 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 expandcollapse popup#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
au3scr Posted January 19, 2008 Author Posted January 19, 2008 Got it If $var = 0 Then $var = 1 MsgBox (64,"clicked","Clicked") Else $var = 0 MsgBox (64,"Unclicked","UnClicked") EndIf
Valuater Posted January 19, 2008 Posted January 19, 2008 expandcollapse popup#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)
Valuater Posted January 19, 2008 Posted January 19, 2008 A better approach... expandcollapse popup#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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now