theguy0000 Posted March 6, 2006 Posted March 6, 2006 (edited) Well, I want to be able to set variables depending on a string representing their name... What Iwant to is is for the user to input a variable name such as "hi", then the variable $hi will be created and set to a specific value (lets say "hello" in this case). How would I go about doing this? Edited March 6, 2006 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN
Moderators big_daddy Posted March 6, 2006 Moderators Posted March 6, 2006 Maybe something like this? $a_input = InputBox("", "", "Hi") If $a_input <> "" Then Assign ( $a_input, "Hello!") MsgBox(0, "", Eval($a_input)) EndIf
theguy0000 Posted March 6, 2006 Author Posted March 6, 2006 I never knew about assign thanks! (but why the Eval () ?) The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN
jefhal Posted March 7, 2006 Posted March 7, 2006 (edited) Well, I want to be able to set variables depending on a string representing their name...I think you want this: dim $Hi $a_input = InputBox("", "", "Hi") If $a_input <> "" Then assign(eval("a_input"),"hello") MsgBox(0, "", $Hi) EndIf Edited March 7, 2006 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
freanir Posted March 7, 2006 Posted March 7, 2006 (edited) I never knew about assign thanks! (but why the Eval () ?)Eval() returns the value of a variable. Example: $foo = 12 MsgBox(0, 'Test', Eval('foo')) Edited March 7, 2006 by freanir freanir
theguy0000 Posted March 7, 2006 Author Posted March 7, 2006 hmm...what on earth is the point of eval? Why use Eval ('foo') when you can just use $foo? The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN
DaleHohm Posted March 7, 2006 Posted March 7, 2006 hmm...what on earth is the point of eval? Why use Eval ('foo') when you can just use $foo?You can find an example of this being done here in my first UDF (with help from Sven).Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
freanir Posted March 7, 2006 Posted March 7, 2006 hmm...what on earth is the point of eval? Why use Eval ('foo') when you can just use $foo?Why use Assign('foo', 'Test'), when you can use $foo = 'Test' ? freanir
jefhal Posted March 7, 2006 Posted March 7, 2006 Why use Assign('foo', 'Test'), when you can use $foo = 'Test' ? Try these examples and substitute your idea with what's there. You will see the subtle difference. You are not assigning $foo = "test", you are assigning the contents of $foo to a new variable of that name to be equal to "test". Look at the last statement in my code snippet. I show $Hi, not $a_input. Big difference, but requires a specific need to be of use. We thought your question reflected that special need... ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Moderators big_daddy Posted March 7, 2006 Moderators Posted March 7, 2006 I think you want this: dim $Hi $a_input = InputBox("", "", "Hi") If $a_input <> "" Then assign(eval("a_input"),"hello") MsgBox(0, "", $Hi) EndIf This would not work if you didn't know what the user was going to enter. My example will work even if the user enter something other than "Hi".
freanir Posted March 7, 2006 Posted March 7, 2006 (edited) @jefhal: I don't get your point. I know what assign() and eval() are for. My previous post was an answer to a post of theguy0000, who wrote:Why use Eval ('foo') when you can just use $foo?To answer his question I changed it to a question of which he knows the answer. Edited March 7, 2006 by freanir freanir
jefhal Posted March 7, 2006 Posted March 7, 2006 I was answering theguy also. Sorry for the confusion... ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
jefhal Posted March 7, 2006 Posted March 7, 2006 This would not work if you didn't know what the user was going to enter. My example will work even if the user enter something other than "Hi".Good point big_daddy, but what would be the point of going to all that extra work of using assign and eval if he won't know the names of the variables in either case? I guess we'd have to ask theguy. It seems like it would be just as easy to assign variable names $1 $2 $3 .... as people enter their unique values.I know what you mean, though, as I had to declare $Hi before I used it! Hard thing to do if you don't know what it's going to be! ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
theguy0000 Posted March 7, 2006 Author Posted March 7, 2006 Why use Assign('foo', 'Test'), when you can use $foo = 'Test' ? oh lol. I get it, thanks. The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now