MeepZero Posted August 2, 2012 Share Posted August 2, 2012 I'm trying to figure out how to have a field fill itself out when I select a radio button. For example, when the user selects the Kiosk radio button I want the computer name to prefix whatever was typed in with KIOSK At the moment I'm hung up on trying to figure out how to update the input box with the new prefix when selected by the radio buttons. I think I need to put something in the While loop so it updates that field, but I can't figure out what to put in. Any hints on what I'd want to do here? expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <_BatteryQuery.au3> Global $BattStatus, $OldMachine Global $mainwindow, $InUSER, $InPASS, $InOWNER, $BattStatus, $MachineType Global $OutUSER, $OutPASS, $OutOWNER, $OutCompname Global $var = 1 Global $module ;Running a check to see if this is a desktop or laptop $battery = _BatteryQuery() if BitAnd($battery[1],128) Then $BattStatus = 0 ConsoleWrite("No Battery present" & @CRLF) Else $BattStatus = 1 ConsoleWrite("I see a battery" & @CRLF) EndIf ConsoleWrite("BatteryStatus is set to " & $BattStatus & @CRLF) ;These variables are ugly, I'll clean them up later Local $radio1, $radio2, $radio3, $radio4, $radio5, $battery ;Building the GUI $mainwindow = GUICreate("Need Login Credentials", 300, 350) ;Creates a window and assigns it a handle GUICtrlCreateLabel("Enter Information Here...", 30, 10) $okbutton = GUICtrlCreateButton("OK", 115, 300, 60) GUISwitch($mainwindow) GUISetState(@SW_SHOW) GUICtrlCreateLabel("Your Domain Username...", 10, 30, 180) $InUSER = GUICtrlCreateInput("", 10, 45, 275, 20) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlSetTip(-1, "Used in AD authentication") GUICtrlCreateLabel("Your Password...", 10, 70, 180) $InPASS = GUICtrlCreateInput("", 10, 85, 275, 20, $ES_PASSWORD) GUICtrlSetTip(-1, "Used in AD authentication") GUICtrlCreateLabel("Machine Owner's Username...Leave blank if none", 10, 110, 290) $InOwner = GUICtrlCreateInput("", 10, 125, 275, 20) GUICtrlSetTip(-1, "The user this machine will be assigned to") GUICtrlCreateLabel("NOT FUNCTIONING DO NOT USE Computer Name. Leave blank if no change.", 10, 150, 290) $InCompname = GUICtrlCreateInput("", 10, 165, 275, 20) GUICtrlSetTip(-1, "Renames machine to input specified") GUIStartGroup() GUICtrlCreateLabel("Select Machine Type, Select N/A if not listed",10,190,290) $radio1 = GUICtrlCreateRadio("Desktop", 20, 210, 120) $radio2 = GUICtrlCreateRadio("Laptop", 150, 210, 150) $radio3 = GUICtrlCreateRadio("Kiosk", 20, 230, 120) $radio4 = GUICtrlCreateRadio("PC Services", 150, 230, 150) $radio5 = GUICtrlCreateRadio("N/A", 150, 250, 150) If $BattStatus = 0 Then GUICtrlSetState($radio1, $GUI_CHECKED) $MachineType= 1 Else GUICtrlSetState($radio2, $GUI_CHECKED) $MachineType= 2 EndIf ;While loop for the radio buttons, maybe the labels can be processed in here too somehow? While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ConsoleWrite("Closing script" & @CRLF) Exit Case $msg = $OkButton ConsoleWrite("Moving on to next step" & @CRLF) ConsoleWrite($MachineType & @CRLF) GUISetState(@SW_HIDE) ExitLoop Case GUICtrl Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on Desktop.' & @CRLF) $MachineType= 1 Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on Laptop.' & @CRLF) $MachineType = 2 Case $msg = $radio3 And BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on Kiosk.' & @CRLF) $MachineType = 3 Case $msg = $radio4 And BitAND(GUICtrlRead($radio4), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on PC Services.' & @CRLF) $MachineType = 4 Case $msg = $radio5 And BitAND(GUICtrlRead($radio5), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on N/A.' & @CRLF) $MachineType = 5 EndSelect Sleep(10) WEnd ;Spitting all of the data out to console $OutUSER = GUICtrlRead($InUSER) ConsoleWrite('$OutUSER is set to ' & $OutUSER & @CRLF) $OutPASS = GUICtrlRead($InPASS) ConsoleWrite('$OutPASS is set to ' & $OutPASS & @CRLF) $OutOWNER = GUICtrlRead($InOwner) ConsoleWrite('$OutOWNER is set to ' & $OutOWNER & @CRLF) $OutCompname = GUICtrlRead($InCompname) ConsoleWrite('$InCompname is set to ' & $OutCompname & @CRLF) ConsoleWrite('$MachineType is set to ' & $MachineType & @CRLF) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 2, 2012 Moderators Share Posted August 2, 2012 MeepZero,Not knowing which input you want to modify, I have used $InCompname in this example: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> ;#include <_BatteryQuery.au3> Global $BattStatus, $OldMachine Global $mainwindow, $InUSER, $InPASS, $InOWNER, $BattStatus, $MachineType Global $OutUSER, $OutPASS, $OutOWNER, $OutCompname Global $var = 1 Global $module ;Running a check to see if this is a desktop or laptop #cs $battery = _BatteryQuery() if BitAnd($battery[1],128) Then $BattStatus = 0 ConsoleWrite("No Battery present" & @CRLF) Else $BattStatus = 1 ConsoleWrite("I see a battery" & @CRLF) EndIf ConsoleWrite("BatteryStatus is set to " & $BattStatus & @CRLF) #ce ;These variables are ugly, I'll clean them up later Local $radio1, $radio2, $radio3, $radio4, $radio5, $battery ;Building the GUI $mainwindow = GUICreate("Need Login Credentials", 300, 350) ;Creates a window and assigns it a handle GUICtrlCreateLabel("Enter Information Here...", 30, 10) $okbutton = GUICtrlCreateButton("OK", 115, 300, 60) GUISwitch($mainwindow) GUISetState(@SW_SHOW) GUICtrlCreateLabel("Your Domain Username...", 10, 30, 180) $InUSER = GUICtrlCreateInput("", 10, 45, 275, 20) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlSetTip(-1, "Used in AD authentication") GUICtrlCreateLabel("Your Password...", 10, 70, 180) $InPASS = GUICtrlCreateInput("", 10, 85, 275, 20, $ES_PASSWORD) GUICtrlSetTip(-1, "Used in AD authentication") GUICtrlCreateLabel("Machine Owner's Username...Leave blank if none", 10, 110, 290) $InOwner = GUICtrlCreateInput("", 10, 125, 275, 20) GUICtrlSetTip(-1, "The user this machine will be assigned to") GUICtrlCreateLabel("NOT FUNCTIONING DO NOT USE Computer Name. Leave blank if no change.", 10, 150, 290) $InCompname = GUICtrlCreateInput("", 10, 165, 275, 20) GUICtrlSetTip(-1, "Renames machine to input specified") GUIStartGroup() GUICtrlCreateLabel("Select Machine Type, Select N/A if not listed",10,190,290) $radio1 = GUICtrlCreateRadio("Desktop", 20, 210, 120) $radio2 = GUICtrlCreateRadio("Laptop", 150, 210, 150) $radio3 = GUICtrlCreateRadio("Kiosk", 20, 230, 120) $radio4 = GUICtrlCreateRadio("PC Services", 150, 230, 150) $radio5 = GUICtrlCreateRadio("N/A", 150, 250, 150) If $BattStatus = 0 Then GUICtrlSetState($radio1, $GUI_CHECKED) $MachineType= 1 Else GUICtrlSetState($radio2, $GUI_CHECKED) $MachineType= 2 EndIf ;While loop for the radio buttons, maybe the labels can be processed in here too somehow? While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ConsoleWrite("Closing script" & @CRLF) Exit Case $msg = $OkButton ConsoleWrite("Moving on to next step" & @CRLF) ConsoleWrite($MachineType & @CRLF) GUISetState(@SW_HIDE) ExitLoop ;Case GUICtrl Case $msg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED _Prefix("Desktop") ConsoleWrite('You clicked on Desktop.' & @CRLF) $MachineType= 1 Case $msg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED _Prefix("Laptop") ConsoleWrite('You clicked on Laptop.' & @CRLF) $MachineType = 2 Case $msg = $radio3 And BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED _Prefix("Kiosk") ConsoleWrite('You clicked on Kiosk.' & @CRLF) $MachineType = 3 Case $msg = $radio4 And BitAND(GUICtrlRead($radio4), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on PC Services.' & @CRLF) $MachineType = 4 Case $msg = $radio5 And BitAND(GUICtrlRead($radio5), $GUI_CHECKED) = $GUI_CHECKED ConsoleWrite('You clicked on N/A.' & @CRLF) $MachineType = 5 EndSelect Sleep(10) WEnd ;Spitting all of the data out to console $OutUSER = GUICtrlRead($InUSER) ConsoleWrite('$OutUSER is set to ' & $OutUSER & @CRLF) $OutPASS = GUICtrlRead($InPASS) ConsoleWrite('$OutPASS is set to ' & $OutPASS & @CRLF) $OutOWNER = GUICtrlRead($InOwner) ConsoleWrite('$OutOWNER is set to ' & $OutOWNER & @CRLF) $OutCompname = GUICtrlRead($InCompname) ConsoleWrite('$InCompname is set to ' & $OutCompname & @CRLF) ConsoleWrite('$MachineType is set to ' & $MachineType & @CRLF) Func _Prefix($sPrefix) ; Read the content of the input $sText = GUICtrlRead($InCompname) ; If the correct prefix is set then stop here If StringLeft($sText, StringLen($sPrefix)) = $sPrefix Then Return ; If not, then remove the current prefix ElseIf StringLeft($sText, 9) = "Desktop: " Then $sText = StringTrimLeft($sText, 9) ElseIf StringLeft($sText, 8) = "Laptop: " Then $sText = StringTrimLeft($sText, 8) ElseIf StringLeft($sText, 7) = "Kiosk: " Then $sText = StringTrimLeft($sText, 7) EndIf ; Add the new prefix and place the string in the input GUICtrlSetData($InCompname, $sPrefix & ": " & $sText) EndFuncPlease ask if you have any questions. M23  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...
MeepZero Posted August 2, 2012 Author Share Posted August 2, 2012 Awesome, thats a huge help. I'm going to start playing with this and see what else I can do with it. We prefix our machine names with DT, LT, etc for being Desktops Laptops etc. The remainder of the machine name is the serial number of the hardware. So what I'm going to try to figure out is how to have it swap out what is in the box (if the prefix is already there) with the newly selected prefix from the radio buttons. I'll post results if I can get it to work Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 2, 2012 Moderators Share Posted August 2, 2012 MeepZero,how to have it swap out what is in the box (if the prefix is already there) with the newly selected prefix from the radio buttonsThat is exactly what I have given you. M23  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...
MeepZero Posted August 2, 2012 Author Share Posted August 2, 2012 Well...yeah you did actually After fiddling around with it a bit more I was able to get it to look exactly how I wanted it, but you are right it was all there exactly how I needed it. Thanks a ton for this Link to comment Share on other sites More sharing options...
MeepZero Posted August 2, 2012 Author Share Posted August 2, 2012 (edited) What if I wanted to test if the user entered anything into the box and reset the variable to "" if they didn't. I'm thinking maybe have it test the variable and see if there are more than 5 characters in it. If more than 5 than keep it, if less, replace it with an empty string. What kind of exp<b></b>ression would I ues to test for that kind of condition? Edit: looks like StringLen is what I need, doh! Edited August 2, 2012 by MeepZero 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