Jumat, 30 September 2011

Re: [ExcelVBA] Indirect Variables

 

Not quite... it still requires the array index.

I haven't looked at his code, but from what he said,
he's got a large number of variables.
Somehow, he is retrieving a subset of the list of variables
and populating a userform. (so they're no in a predictable order)
The user selects one of the variables from the form,
and he retrieves the value of the variable.

So, what he's doing is something like
Eval(variable)
but, Eval expects the (variable) to resove into a function name and Eval
basically calls the function.
What he's REALLY wanting to do is something line Excel's Indirect() function.
Only with variables instead of cells.

 
Paul
-----------------------------------------
"Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can." - John Wesley
-----------------------------------------

________________________________
From: Jignesh Parikh <jignesh.parikh76@gmail.com>
To: ExcelVBA@yahoogroups.com
Sent: Fri, September 30, 2011 8:54:54 AM
Subject: Re: [ExcelVBA] Indirect Variables

 
Hi Paul,

You can try something like this.

Function TestVar(Var As Integer)
Dim ttext(20) As String
ttext(1) = "Aaple"
ttext(2) = "banana"
ttext(3) = "carrot"
TestVar = ttext(Var)
End Function

Regards,

Jignesh Parikh.

----- Original Message -----
From: paulschreinerindy
To: ExcelVBA@yahoogroups.com
Sent: Friday, September 30, 2011 5:25 PM
Subject: [ExcelVBA] Indirect Variables

I have a co-worker that has come to me with a question.
I'm pretty sure I've done this in the past, but
I cannot seem to locate it in my 80,000 lines of VBA code!

We have several variables:
Val1 = "apple"
Val2 = "banana"
Val3 = "carrot"

there is another variable that will result in
having the value of one of these variable NAMES.

TestVar = "Val2"

How do we determine the value of the variable
represented by the value of TestVar?

That is: msgbox val(TestVar)
displays: "banana"

(similar to the INDIRECT() function in Excel, but for variables)

Paul

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar