Jump to content
The-dude

GUI with multiple inputs - (Moved)

Recommended Posts

Hi Guys,

I'm trying to create a GUI with multiple text input boxes and when button1 is pressed it combines all the input text boxes into one text string (in the format I want, see below) and waits for a windows "Save As" dialogue to pop-up and then sends the text string to the "Save As" box (for the file name) and then presses save. 

I want the text string, with underscores, to read like this-  TEST#_TEMP_PSI_DWELL_DATE.xlsx 

Here's what I've got so far... I just can't seem to figure out how to combine the multiple inputs and have the script hold the data until the windows "Save As" box pops up to send. I was initially thinking that saving the text string to a notepad file somewhere and recalling the data once the "Save As" box pops up by just copying and pasting the text into the window would work - there's a saveas dialague in the below script that I don't need since the "file name text string" would be overwrote after every "Button1" was pressed . I know there's a much easier way to do this, any help would be GREATLY appreciated. 

 #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region 
$Form1_1 = GUICreate("Testing", 278, 218, 230, 181)
$Input1 = GUICtrlCreateInput("", 56, 40, 185, 21)
$Input2 = GUICtrlCreateInput("", 56, 64, 185, 21)
$Input3 = GUICtrlCreateInput("", 56, 88, 185, 21)
$Input4 = GUICtrlCreateInput("", 56, 112, 185, 21)
$Label1 = GUICtrlCreateLabel("TEST#", 16, 43, 39, 17)
$Label2 = GUICtrlCreateLabel("TEMP", 16, 68, 34, 17)
$Label3 = GUICtrlCreateLabel("PSI", 24, 92, 21, 17)
$Label4 = GUICtrlCreateLabel("DWELL", 8, 115, 42, 17)
$Button1 = GUICtrlCreateButton("START TEST", 56, 144, 75, 25)
GUICtrlSetBkColor(-1, 0x008000)
$Button2 = GUICtrlCreateButton("STOP TEST", 168, 144, 75, 25)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xFF0000)
$Input5 = GUICtrlCreateInput(@MON & "/" & @MDAY & "/" & @YEAR, 56, 16, 185, 21)
$DATE = GUICtrlCreateLabel("DATE", 16, 20, 33, 17)
$Label5 = GUICtrlCreateLabel("Created by Me", 8, 200, 150, 17)
GUISetState(@SW_SHOW)
#EndRegion 

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $DataFromUser = GUICtrlRead($Input1)
            $SaveLocation = FileSaveDialog('Save File', @ScriptDir, 'Text Files (*.txt)', 16)
            FileWrite($SaveLocation, $DataFromUser)
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Share this post


Link to post
Share on other sites

Here's one way:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region
$Form1_1 = GUICreate("Testing", 278, 218, 230, 181)
$Input1 = GUICtrlCreateInput("", 56, 40, 185, 21)
$Input2 = GUICtrlCreateInput("", 56, 64, 185, 21)
$Input3 = GUICtrlCreateInput("", 56, 88, 185, 21)
$Input4 = GUICtrlCreateInput("", 56, 112, 185, 21)
$Label1 = GUICtrlCreateLabel("TEST#", 16, 43, 39, 17)
$Label2 = GUICtrlCreateLabel("TEMP", 16, 68, 34, 17)
$Label3 = GUICtrlCreateLabel("PSI", 24, 92, 21, 17)
$Label4 = GUICtrlCreateLabel("DWELL", 8, 115, 42, 17)
$Button1 = GUICtrlCreateButton("START TEST", 56, 144, 75, 25)
GUICtrlSetBkColor(-1, 0x008000)
$Button2 = GUICtrlCreateButton("STOP TEST", 168, 144, 75, 25)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xFF0000)
$Input5 = GUICtrlCreateInput(@MON & "/" & @MDAY & "/" & @YEAR, 56, 16, 185, 21)
$DATE = GUICtrlCreateLabel("DATE", 16, 20, 33, 17)
$Label5 = GUICtrlCreateLabel("Created by Me", 8, 200, 150, 17)
GUISetState(@SW_SHOW)
#EndRegion

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE
               Exit
          Case $Button1
               $DataFromUser = GUICtrlRead($Input1) & "_" & GUICtrlRead($Input2) & "_" & GUICtrlRead($Input3) & "_" & GUICtrlRead($Input4) &
               $SaveLocation = FileSaveDialog('Save File', @ScriptDir, 'Text Files (*.txt)', 16)
               FileWrite($SaveLocation, $DataFromUser) 
     EndSwitch
WEnd

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks BrewManNH! This has created the workaround scenario I was wanting as a last resort. What if I wanted to just skip the whole writing to a text document and have the script store the data and then send it as soon as a "Save As" window pops up?

Share this post


Link to post
Share on other sites

Use Send or better ControlSend instead of  FileWrite.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewManNH Thank you for all your help! Do you mind showing me how that ControlSend script would look like? The script I'm writing in this help post will be activating another script using a "run" function which that other script will in turn create a "Save As" window at some point and I want this this script to send the data to the file name input box on the "Save As" window. 

Share this post


Link to post
Share on other sites

Ah! I think I have it-

 

 Case $Button1
               $DataFromUser = GUICtrlRead($Input1) & "_" & GUICtrlRead($Input2) & "_" & GUICtrlRead($Input3) & "_" & GUICtrlRead($Input4)& "_" & GUICtrlRead($Input5)
               WinWaitActive("Save As")
               Sleep(1000)
               Send($DataFromUser)

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

×
×
  • Create New...