Jump to content

[solved] Reading multiple values from one GUI - basic query


saywell
 Share

Recommended Posts

I'm trying to write a script that starts with a GUI to determine several user choices. I need to read each of those choices into its own variable, which the script will then use to create a document.

I've searched the helpfiles, and whilst the answer might be there, it's not clear to me!

The examples all show how to get a result from a GUI with a single input.

The GUI tutorial example show well how to create multiple inputs in one GUI, but unfortunately stops short of showing/telling you how to read those various inputs.

Here is my GUI:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <String.au3>
#Include <Array.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
$mainwindow = GUICreate("Clinical Document Manager", 375, 420, -1, -1) 

GUICtrlCreateLabel("Please complete details in top section ", 25, 5)
GUICtrlCreateLabel("then choose an option from the lower section", 25, 20)

GUICtrlCreateLabel("________________________________________________________________________", 0, 270)

$Create = GUICtrlCreateButton("Create Letter", 80, 300, 200)
GUICtrlSetOnEvent($Create, "Create")
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState(@SW_SHOW)

$radio1 = GUICtrlCreateRadio("Clinic Letter", 10, 40, 120, 20)
$radio2 = GUICtrlCreateRadio("Discharge Summary", 10, 55, 120, 20)
$radio3 = GUICtrlCreateRadio("Other Clinician letter", 10, 70, 120, 20)
$radio4 = GUICtrlCreateRadio("Patient letter", 10, 85, 120, 20)
$radio5 = GUICtrlCreateRadio("Referral letter", 10, 100, 120, 20)

$sAuthor = GUICtrlCreateCombo("Author    ", 240, 45, 120, 100) ; create first item
    GUICtrlSetData(-1, "WRS|NCGB|JCH|CT|MH|CH|RC");, "           ") ; add other item snd set a new default
    
$sSecretary = GUICtrlCreateCombo("Secretary   ", 240, 75, 120, 100) ; create first item
    GUICtrlSetData(-1, "JB|KP|CM|GR")
    
GUICtrlCreateLabel("Patient Details", 25, 130)
$sNHSnumber = GuiCtrlCreateInput("NHS Number", 165, 145, 130, 20)
$sHSP = GuiCtrlCreateInput("Hospital Number", 25, 145, 130, 20)
$sFirstName = GuiCtrlCreateInput("First Name", 25, 165, 130, 20)
$sLastName = GuiCtrlCreateInput("Last Name", 165, 165, 130, 20)

    ;----------------------------------

GUICtrlCreateLabel("Demo system", 28, 355)
GUICtrlCreateLabel("Yeovil District Hospital NHS Foundation Trust", 28, 370)
GUICtrlCreateLabel("Thrown together by W. R. Saywell", 28, 400)
GUISetHelp ( 'notepad.exe "c:\program_files\scripts\encryption_help.txt"' )


; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Func Create()

;  I need to read all the inputs  here, so I can use the variables to later in the script
;  when the CREATE LETTER button is clicked




EndFunc


Func CLOSEClicked()
        Exit
EndFunc

If anyone can give me a steer in the right direction I'd be very grateful!

Regards,

William

Edited by saywell
Link to comment
Share on other sites

First, though it doesn't fail in this context, you can't use GuiGetMsg() when using Event Mode for your GUI. So just to avoid confusion, do something like this instead:

; Wait for GUI Events
GuiSetState()
While 1
     Sleep(10)
WEnd

Next, you have basic controls (radio buttons, combo boxes, and inputs) that can each be read with GuiCtrlRead(). So what's your issue with using GuiCtrlRead()?

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

So what's your issue with using GuiCtrlRead()?

Thanks. My problem is how to read each one (sequentially or simultaneously - I presume the former) into its respective variable. The help examples are in a single item context - for example

Do
        $msg = GUIGetMsg()
        If $msg = $n2 Then
            MsgBox(0, "Selected listbox entry", GUICtrlRead($n1)) ; display the selected listbox entry
            $menustate = GUICtrlRead($menu1) ; return the state of the menu item
            $menutext = GUICtrlRead($menu1, 1) ; return the text of the menu item
            MsgBox(0, "State and text of the menuitem", "state:" & $menustate & @LF & "text:" & $menutext)
        EndIf
    Until $msg = $GUI_EVENT_CLOSE

This responds to entries when they occur, whereas I want to read all the settings but only when my button is pressed (activating a function). That's where I'm adrift at present.

William

Link to comment
Share on other sites

Assign a variable to each value you need, and do as many GuiCtrlRead()'s as you need to get all the values required.

I still don't see why that's a problem.

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks.

You don't see why it's a problem because you know how to do it!!!

But I don't [yet].

How do I read each one individually - eg 1st GuiCtrlRead() to get value for the radio buttons, then next GuiCtrlRead() for the secretary etc?

Ie how do you identify which control each GuiCtrlRead() is reading? None of the examples I could find in the help files tells you how to do this, as they all read one control only.

William

Link to comment
Share on other sites

For each control you make it return a handles to use when you want to read it

$sNHSnumber = GuiCtrlCreateInput("NHS Number", 165, 145, 130, 20)

^Handle___________^ control creation

Guictrlread works by using the control handles to identify which its read and returns what is read

$ReadNHSnumber = GUICtrlRead($sNHSnumber)

^Whats read_____________________^Handle of control to read

for the follow controls

$sNHSnumber = GuiCtrlCreateInput("NHS Number", 165, 145, 130, 20)
$sHSP = GuiCtrlCreateInput("Hospital Number", 25, 145, 130, 20)
$sFirstName = GuiCtrlCreateInput("First Name", 25, 165, 130, 20)
$sLastName = GuiCtrlCreateInput("Last Name", 165, 165, 130, 20)

you would read them all by doing

$ReadNHSnumber = GUICtrlRead($sNHSnumber)
$ReadHSP = GUICtrlRead($sHSP)
$ReadFirstName = GUICtrlRead($sFirstName)
$ReadLastName = GUICtrlRead($sLastName)
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

For each control you make it return a handles to use when you want to read it

$sNHSnumber = GuiCtrlCreateInput("NHS Number", 165, 145, 130, 20)

^Handle___________^ control creation

Guictrlread works by using the control handles to identify which its read and returns what is read

$ReadNHSnumber = GUICtrlRead($sNHSnumber)

^Whats read_____________________^Handle of control to read

for the follow controls

$sNHSnumber = GuiCtrlCreateInput("NHS Number", 165, 145, 130, 20)
$sHSP = GuiCtrlCreateInput("Hospital Number", 25, 145, 130, 20)
$sFirstName = GuiCtrlCreateInput("First Name", 25, 165, 130, 20)
$sLastName = GuiCtrlCreateInput("Last Name", 165, 165, 130, 20)

you would read them all by doing

$ReadNHSnumber = GUICtrlRead($sNHSnumber)
$ReadHSP = GUICtrlRead($sHSP)
$ReadFirstName = GUICtrlRead($sFirstName)
$ReadLastName = GUICtrlRead($sLastName)

Thanks. Yoris - you're a star.

I see now why PsaltyDS thought it was easy - it is indeed easy, and I think I was so close but failed to put the last bit together.

It would have been helpful to have had this info added to the end of the Sample Controls code snippet in the helpfiles, as it doesn't seem to be spelt out anywhere! Whilst it might be obvious to the more experienced, they won't be the main users of the helpfiles.

Regards,

William

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