xTheRedHandX Posted September 25, 2012 Share Posted September 25, 2012 I'm very new to scripting and AutoIt. I'm trying to create a script where if the radio button is select then "install network printer as default" else "install network printer. Once again I am a Noob. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $Radio1 = GUICtrlCreateRadio("Click Button Before Selecting Printer to Make that Printer Default", 24, 320, 569, 17) GUICtrlSetOnEvent(-1, "Radio1") GUICtrlSetFont(-1, 12, 800, 0, "Georgia") GUISetState(@SW_SHOW) Func Button1Click() If $Radio1 = "IsChecked" then Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /in /y /n\\server\printer', "",@SW_HIDE) Else Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /in /y /n\\server\printer', "",@SW_HIDE) Endif EndFunc Any Help would be appreciated. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 25, 2012 Moderators Share Posted September 25, 2012 (edited) xTheRedHandX, This should give you the idea: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Radio1 = GUICtrlCreateRadio("Click Button Before Selecting Printer to Make that Printer Default", 10, 10, 400, 20) GUICtrlCreateButton("Run", 10, 50, 80, 30) GUICtrlSetOnEvent(-1, "Button1Click") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func Button1Click() If GUICtrlRead($Radio1) = 1 Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox(0, "Radio", "Selected") ;Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /in /y /nserverprinter', "", @SW_HIDE) Else MsgBox(0, "Radio", "Not Selected") ;Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /in /y /nserverprinter', "", @SW_HIDE) EndIf Exit EndFunc ;==>Button1Click Func _Exit() Exit EndFunc All clear? M23 Edit: Welcome to the AutoIt forum, by the way! Edited September 25, 2012 by Melba23 Obvious I would have thought! 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jazzyjeff Posted September 25, 2012 Share Posted September 25, 2012 Your script is very incomplete. This should work. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 149, 105, 192, 124) $Radio1 = GUICtrlCreateRadio("Click Button Before Selecting Printer to Make that Printer Default", 16, 16, 113, 17) GUICtrlSetFont(-1, 12, 800, 0, "Georgia") $Button1 = GUICtrlCreateButton("Set Default Printer", 16, 72, 115, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Button1Click() EndSwitch WEnd Func Button1Click() $radioChk = GUICtrlRead($Radio1) If $radioChk = 1 Then Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /in /y /nserverprinter', "",@SW_HIDE) Else Run(@ComSpec & " /c " & 'rundll32 printui.dll,PrintUIEntry /in /y /nserverprinter', "",@SW_HIDE) EndIf EndFunc There are many ways to do this, and the help file will show you a different way. You need to determine what works best for you. Link to comment Share on other sites More sharing options...
jazzyjeff Posted September 25, 2012 Share Posted September 25, 2012 Sorry wasn't trying to copy here. I just saw Mebla's reply. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 25, 2012 Moderators Share Posted September 25, 2012 jazzyjeff,It happens all the time. I just think "Great minds...." *. M23* And not Thomas Paine's version - an early version of "two countries separated by a common language". 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
xTheRedHandX Posted September 25, 2012 Author Share Posted September 25, 2012 Thanks Melba23 and jazzyjeff, They both worked. Yeah I only posted the parts of the script that I was having problems with. Thanks again. Link to comment Share on other sites More sharing options...
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