Sign in to follow this  
Followers 0
MeepZero

How to write to a field when another GUI element is invoked?

6 posts in this topic

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?

#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)

Share this post


Link to post
Share on other sites



MeepZero,

Not knowing which input you want to modify, I have used $InCompname in this example: ;)

#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)
EndFunc

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

 

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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 buttons

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

 

Share this post


Link to post
Share on other sites

Well...yeah you did actually :idiot:

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 :D

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by MeepZero

Share this post


Link to post
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
Sign in to follow this  
Followers 0