Jump to content

Help with Radio Button


Recommended Posts

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

  • Moderators

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 by Melba23
Obvious I would have thought!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

jazzyjeff,

It happens all the time. I just think "Great minds...." *. :D

M23

* And not Thomas Paine's version - an early version of "two countries separated by a common language". ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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