Sign in to follow this  
Followers 0
cppman

Displaying A Variable

29 posts in this topic

#1 ·  Posted (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 by CHRIS95219

Share this post


Link to post
Share on other sites



$MyVar = "MyString"

msgbox('','', $MyVar)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

MsgBox (0, "$MyVar", $MyVar)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by greenmachine

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by CHRIS95219

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

CHRIS95219, maybe this: _ShowVar(String($MyVar))

edit: woops, ignore. :)

Edited by forger

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by CHRIS95219

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (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
EndFunc
Edit: Only works when not compiled

Edit2: Needed to trim the $ off $readvar in order to eval it

Edited by gamerman2360

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

$MyVar = "$MyVar"

msgbox('','', $MyVar)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

I really don't think there is a reason to ever use this.

Share this post


Link to post
Share on other sites

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)....

Share this post


Link to post
Share on other sites

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...

[center]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.[/center]

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#16 ·  Posted (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 by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

"Displaying A Variable, hmmmm..."

man.... i'm lost

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

"Displaying A Variable, hmmmm..."

man.... i'm lost

8)

I think the original poster was lost too....

I don't know how many right answers he needs, but this many seems like enough.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Global $MyVar
If Assign("MyVar", "$MyVar") Then MsgBox(4096, "$MyVar", $MyVar)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

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...

[center]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.[/center]

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