Jump to content

Displaying A Variable


Recommended Posts

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
Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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)....

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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

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.

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...