Sign in to follow this  
Followers 0
jbsoccerbrit

Get value of text box to assign to variable

15 posts in this topic

#1 ·  Posted (edited)

Sorry for the very newbie like question but I was wondering how you get the value of a text box and assign it as a variable value.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icons\images\settings.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


;Title and GUI display for tool
$CopyPaste = GUICreate("Convert Tool", 240, 80, 180, 124)
GUISetState(@SW_SHOW)

;Primary Files Label
$Label1 = GUICtrlCreateLabel("Options:", 10, 4, 151, 20)

;Creates a button(S) $assigns var name
$TEXTBOX1 = GUICtrlCreateInput("", 10, 20, 45, 20, 1)
$TEXTBOX2 = GUICtrlCreateInput("", 10, 40, 45, 20, 1)


While 1
    $msg = GUIGetMsg()

        Switch $msg
    Case $GUI_EVENT_CLOSE ;closes when red x is pressed
    Exit

            Case $TEXTBOX1 ;does stuff
FileCopy( "C:\folder1\TEXTBOX1 VALUE HERE", "C:\folder2\TEXTBOX2 VALUE HERE", 1)


EndSwitch

    WEnd


;Displays the GUI until told to close
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by jbsoccerbrit

Share this post


Link to post
Share on other sites



Look at the doc's for GUICtrlRead ()

Share this post


Link to post
Share on other sites

Will do thank you :idea:

Share this post


Link to post
Share on other sites

Still at a loss I guess... I understand the Read, Reads in the value but not sure how to place the value where it needs to be.

Share this post


Link to post
Share on other sites

Tip for the future:

*If you would use Help and search for GuiCtrlRead you would notice, that abit down, there is Related section, you could find function called GUICtrlSetData there.

Share this post


Link to post
Share on other sites

Just read the area and all it appears to do for me is explain how to make a drop down menu with selections. I am looking to pass a value from a text box as a variable, so I don't see how the two relate.

I guess I am looking more for some coding examples or direction... Thanks for the suggestion Makaule :idea:

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sounds like you may need more of an intro to programming in general than specific AutoIt instruction. There are several good compilations catered to new programmers using AutoIt, see the wiki: http://www.autoitscript.com/wiki/Tutorials .

The simple explanation for what you seem to be saying is a simple variable assignment...

$someControl =   GUICtrlCreateInput ("test text",0,0)
$someText = GUICtrlRead($someControl)
MsgBox(0,"",$someText)
Edited by evilertoaster

Share this post


Link to post
Share on other sites

Maybe I can explained better... I understand the GUICtrlRead reads the information from where I ask it to, like the example above. However my problem is getting that read information to be a variable in this line of code below.

FileCopy( "C:\folder\filename.ext", "new folder", 1)

I want one box to be a variable for the extension on the end of the file name ("C:\folder\filename.VARIABLE 1 GOES HERE FROM INPUT IN TEXT BOX 1") and then the "New Folder" section would be read in from a second text box.

Box 1 [] = Where you type in ext

Box 2 [] = Destination folder

If that makes better sense.

Share this post


Link to post
Share on other sites

One you use GUICtrlRead to assign the values to a variable (say $fileName, and $fileExt), you can append them to your FileCopy arguments like so:

FileCopy( "C:\folder\"&$fileName&"."&$fileExt, "new folder", 1)

Share this post


Link to post
Share on other sites

Awesome exactly what I was looking for.

Thank you for helping me out with this, greatly appreciated :idea:

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I guess I just dont know enough AUTOIT syntax because I cant figure out how to set the destination folder based on the same method.

Maybe

FileCopy( "C:\folder\name."&$fileExt, ""&$TEXT2&", 1)

Edited by jbsoccerbrit

Share this post


Link to post
Share on other sites

AutoIt's syntax is nothing special, which is why I speculate it might be worth your time to read a good tutorial.

Quotes designate a string. so when you write "some text here" you start and end with quotes. 2 quotes back to back (such as "") is an empty string (nothing). Quotes must always be used in pairs though, unlike your code below:

FileCopy( "C:\folder\name." & $fileExt, "" & $TEXT2 & ", 1)

which should be:

FileCopy( "C:\folder\name." & $fileExt, $TEXT2, 1)

This assumes $TEXT2 is the full path to the directory you're wanting to copy to.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Here is the code I have I don't understand why it doesnt work

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icons\images\settings.ico
#AutoIt3Wrapper_outfile=S:\folder\test.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


;Title and GUI display for tool
$CopyPaste = GUICreate("Var Grab", 240, 120, 180, 124)
GUISetState(@SW_SHOW)

;Primary Files Label
$Label1 = GUICtrlCreateLabel("Options:", 10, 4, 151, 20)
$Label2 = GUICtrlCreateLabel("Source Folder", 60, 20, 151, 20)
$Label3 = GUICtrlCreateLabel("File Extension Type", 60, 45, 151, 20)
$Label4 = GUICtrlCreateLabel("Destination Folder", 65, 70, 151, 20)

;Creates a button(S) $assigns var name
$TEXT1 = GUICtrlCreateInput("", 10, 20, 45, 20, 1)
$TEXT2 = GUICtrlCreateInput("", 10, 45, 45, 20, 1)
$TEXT3 = GUICtrlCreateInput("", 10, 70, 55, 20, 1)
$ACTION = GUICtrlCreateButton("Convert", 10, 95, 45, 20, 1)


While 1
    $msg = GUIGetMsg()

        Switch $msg
    Case $GUI_EVENT_CLOSE ;closes when red x is pressed
    Exit

Case $ACTION
FileCopy( "C:\"&$TEXT1&"\Filename" & $TEXT2, $TEXT3, 1)


EndSwitch

    WEnd


;Displays the GUI until told to close
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

For TEXT1 I enter the folder names and as long as it exists on c:\ it should work

for TEXT2 I enter .ext - so as long as the file filename with the extension i type in it should find it

for TEXT3 I enter the new folder location and as long as it exists it should move it

Edited by jbsoccerbrit

Share this post


Link to post
Share on other sites

Forgetting the GUICtrlRead... so it seems

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