Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 dim array with varible names and values 1

Status
Not open for further replies.

imarosel

Technical User
Jun 23, 2005
149
US
I want to strip what is in the first dimension of this array out as a variable and assign it the value that is in the second dimension so a forumula can run variables.

valueArray:
(x,2)
(y,3)

For varAssign = 1 To UBound(valueArray) + 1
valueArray(1, varAssign).Value = valueArray(2, varAssign)
Next

i want the loop above to do the equivalent of
x=2
y=3

so that the following can be run
eqn = x & "^2+" & y & "^2
 
imarosel
Huh.
Code:
Function ArrayThing()
Dim valueArray(1 To 2, 1 To 2)
Dim varAssign
Dim eqn As String
valueArray(1, 1) = "x"
valueArray(1, 2) = 2
valueArray(2, 1) = "y"
valueArray(2, 2) = 3
eqn = "x^2+y^2"
For varAssign = 1 To UBound(valueArray)
   eqn = Replace(eqn, valueArray(varAssign, 1), valueArray(varAssign, 2))
Next
ArrayThing = Evaluate(eqn)
End Function

Uses the Excel [tt]Evaluate()[/tt] function and when tested returned 13.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
this is interesting, it might actually make a differnt idea i have possible. I'm going to play with this thanks. I know what I am doing seems strange, but I have some strange constraints on me.
 
yea yea yea this actually enabled me to go back to my first design, I don't know much VB. You rock the House! Have a good weekend.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top