cppman Posted April 6, 2006 Posted April 6, 2006 (edited) I was'nt too sure how i would do this, so it here it goes: Im trying to display a message box, with the VARIABLE NAME(not value) of what the user typed in... like say they do this: $MyVar = "MyString" _ShowVar($MyVar) how can i get what the VARIABLE NAME($MyVar) instead of the VALUE("MyString") ????? Edited April 6, 2006 by CHRIS95219 Miva OS Project
cppman Posted April 6, 2006 Author Posted April 6, 2006 I don't think u guys understood me completely. sry if i did'nt make myself clear. I wanted to make the text in the message box actually say, "$WhateverTheVariableIs". not the value of that variable. say they do. _ShowVar($Variable) a message box will come up and say: "$Variable". not the value. Miva OS Project
greenmachine Posted April 6, 2006 Posted April 6, 2006 (edited) I put it in the title, so what. It is what you want. But if you're doing a function that passes a variable, you're actually just passing the stuff in the variable, so it isn't going to work like that. Edited April 6, 2006 by greenmachine
cppman Posted April 6, 2006 Author Posted April 6, 2006 (edited) but then how would i use it for this, because u have it in quotes... func _ShowVar($variable) msgbox(0, "$variable", "") EndFunc _ShowVar($ThisIsAVariable) it will always show, "$variable" in the message box, and not "$ThisIsAVaraible". **ok, u beat me to it. lol alright, thanks, thats what i was wondering. is their any other way of doing something like that? without them having to type in the variable as a string? Edited April 6, 2006 by CHRIS95219 Miva OS Project
forger Posted April 6, 2006 Posted April 6, 2006 (edited) CHRIS95219, maybe this: _ShowVar(String($MyVar)) edit: woops, ignore. Edited April 6, 2006 by forger
cppman Posted April 6, 2006 Author Posted April 6, 2006 (edited) that'll display the value of that variable. thanks though. nvm... lol, i got beat again. u edited while i was still posting..... Edited April 6, 2006 by CHRIS95219 Miva OS Project
greenmachine Posted April 6, 2006 Posted April 6, 2006 Can I ask why you'd need this? Just thought (duh...) why not just put the var is quotes when you send it to the function. That way you're passing a literal string - the name of the variable.
gamerman2360 Posted April 6, 2006 Posted April 6, 2006 (edited) if you really needed to:$MyVar = 2 MsgBox(0, "Example", _ShowVar($MyVar, @ScriptLineNumber)) Func _ShowVar($MyVar, $ScriptLineNumber) $i = 0 While 1 $i += 1 If Not IsDeclared("_ShowVarVar" & $ScriptLineNumber & ":" & $i) Then Assign("_ShowVarVar" & $ScriptLineNumber & ":" & $i, "", 2) $case = $i ExitLoop EndIf WEnd $file = FileRead(@ScriptFullPath) If StringReplace($file, @CRLF, "") <> $file Then $delimiter = @CRLF ElseIf StringReplace($file, @CR, "") <> $file Then $delimiter = @CR Else $delimiter = @LF EndIf $filearray = StringSplit($file, $delimiter, 1) $linearray = StringSplit($filearray[$ScriptLineNumber], "_ShowVar(", 1) $readvar = StringLeft($linearray[$case + 1], StringInStr($linearray[$case + 1], ",") - 1) If Not ($MyVar == Eval(StringTrimLeft($readvar, 1))) Then SetError(1) Return $readvar EndFuncEdit: Only works when not compiled Edit2: Needed to trim the $ off $readvar in order to eval it Edited April 6, 2006 by gamerman2360
Valuater Posted April 6, 2006 Posted April 6, 2006 (edited) $MyVar = "$MyVar" msgbox('','', $MyVar) 8) Edited April 6, 2006 by Valuater
gamerman2360 Posted April 6, 2006 Posted April 6, 2006 I really don't think there is a reason to ever use this.
greenmachine Posted April 6, 2006 Posted April 6, 2006 I really don't think there is a reason to ever use this.Exactly... seems like if you're the one making the script, and you have access to all the variables, that you could just do like my first post and get the job done. I really don't see what's wrong with a simple: MsgBox (0, "$MyVar", $MyVar)....
Moderators SmOke_N Posted April 6, 2006 Moderators Posted April 6, 2006 I really don't think there is a reason to ever use this.I can think of one reason, but it isn't very ethical... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
gamerman2360 Posted April 6, 2006 Posted April 6, 2006 I can think of one reason, but it isn't very ethical... Care to elaborate? Even if you weren't making the script, say it was generated automatically, you could still have the var wrapped in quotes.
Moderators SmOke_N Posted April 6, 2006 Moderators Posted April 6, 2006 (edited) Care to elaborate? Even if you weren't making the script, say it was generated automatically, you could still have the var wrapped in quotes.Well, when I first saw the question, the first thing I thought of was why not just use an array... Edit:Edited the remainder, don't want to give anyone any ideas Edited April 6, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Valuater Posted April 6, 2006 Posted April 6, 2006 "Displaying A Variable, hmmmm..." man.... i'm lost 8)
greenmachine Posted April 6, 2006 Posted April 6, 2006 "Displaying A Variable, hmmmm..."man.... i'm lost8)I think the original poster was lost too....I don't know how many right answers he needs, but this many seems like enough.
Valuater Posted April 6, 2006 Posted April 6, 2006 (edited) Global $MyVar If Assign("MyVar", "$MyVar") Then MsgBox(4096, "$MyVar", $MyVar) 8) Edited April 6, 2006 by Valuater
Moderators SmOke_N Posted April 6, 2006 Moderators Posted April 6, 2006 Global $MyVar If Assign("MyVar", "MyVar") Then MsgBox(4096, "MyVar", $MyVar) 8)I think the point here, is he doesn't know what the Var is going to be, otherwise... why would you need to know the name, you already do... But I could be way off... Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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