Sign in to follow this  
Followers 0
Morthawt

Is it possible to have user input decide a variable name?

9 posts in this topic

Is it possible to have a function that accepts an input from the user and use that input to output its results to? I mean for example:

Func Test($input)

Then that $input (containing the name of the variable we want to use in the program) be translated some how so it can be used as a variable in that function? So I could output the results from that function to $ohyeah or $bang or what ever I typed into an input box to be sent into there under the $input of the function?

Share this post


Link to post
Share on other sites



Morthawt,

I am somewhat bemused as exactly what you have asked in your question, but I think this shows how to do it: :)

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hInput = GUICtrlCreateInput("", 10, 10, 200, 20)
$hButton = GUICtrlCreateButton("Do It!", 10, 50, 80, 30)
$hLabel = GUICtrlCreateLabel("", 10, 100, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Call function with content of input
            $iLength = _Function(GUICtrlRead($hInput))
            ; Use the returned value to refill the input
            GUICtrlSetData($hInput, $iLength)
    EndSwitch

WEnd

Func _Function($sString)

    ; A simple function
    Return StringLen($sString)

EndFunc

If not, please explain more clearly what it is you want. :mellow:

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

#3 ·  Posted (edited)

You mean something like that?

$input = InputBox("Test", "Enter something", "", "", "", 130)
Assign($input & "$", "Test", 1) ;this will create a variable with the name you entered and assign test to it
MsgBox(0, "Test", Eval($input & "$"))

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Morthawt,

I am somewhat bemused as exactly what you have asked in your question, but I think this shows how to do it: :)

#include <GUIConstantsEx.au3>
 
$hGUI = GUICreate("Test", 500, 500)
 
$hInput = GUICtrlCreateInput("", 10, 10, 200, 20)
$hButton = GUICtrlCreateButton("Do It!", 10, 50, 80, 30)
$hLabel = GUICtrlCreateLabel("", 10, 100, 200, 20)
 
GUISetState()
 
While 1
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            ; Call function with content of input
            $iLength = _Function(GUICtrlRead($hInput))
            ; Use the returned value to refill the input
            GUICtrlSetData($hInput, $iLength)
    EndSwitch
 
WEnd
 
Func _Function($sString)
 
    ; A simple function
    Return StringLen($sString)
 
EndFunc

If not, please explain more clearly what it is you want. :mellow:

M23

Err yea I don't think thats it. Here is an example. I make a function called ObtainInput($data) well I want to be able to call that function with something like ObtainInput('password') and the output it ends up with will be sent to $password or call the function like this ObtainInput('personsname') and it will output their name they typed into the input box to the $personsname variable.

Share this post


Link to post
Share on other sites

You mean something like that?

$input = InputBox("Test", "Enter something", "", "", "", 130)
Assign($input & "$", "Test", 1) ;this will create a variable with the name you entered and assign test to it
MsgBox(0, "Test", Eval($input & "$"))

Br,

UEZ

I just tested this but it seems to not make a variable with the name. I added at the top of your code Global $ding and then added another message box at the end displaying $ding. Then I typed ding into the box and your box came up with test but my box was empty.

Share this post


Link to post
Share on other sites

you mean something like:

$password= (GUICtrlRead($Input1))

this assigns whatever is in the input box to the $password variable.

might not be that simple though.

Share this post


Link to post
Share on other sites

you mean something like:

$password= (GUICtrlRead($Input1))

this assigns whatever is in the input box to the $password variable.

might not be that simple though.

That code will just assign the value from a GUI input box to a preset $password variable. What I am talking about is having the "$password" variable NAME set by what ever is typed in the input box so if I type in "chicken" then the next input I type will go into a $chicken variable.

Share this post


Link to post
Share on other sites

hello Morthawt,

Assign is indeed the function you're looking for, try this demo:

$sVarName = InputBox("", "Enter variable name:")
Assign($sVarName, InputBox("", "Enter value:"))
MsgBox(64, "", "Content of $" & $sVarName & " is " & Eval($sVarName))

Hope this helps :mellow:

Share this post


Link to post
Share on other sites

hello Morthawt,

Assign is indeed the function you're looking for, try this demo:

$sVarName = InputBox("", "Enter variable name:")
Assign($sVarName, InputBox("", "Enter value:"))
MsgBox(64, "", "Content of $" & $sVarName & " is " & Eval($sVarName))

Hope this helps :mellow:

Entered Glass in first Input and Beer in second. Output = Content of $Glass is Beer :) I'm thursty now!

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