Executing a the value of a string variable

AlisonP
AlisonP used Ask the Experts™
on
I was wondering if it was possible to execute a string variable's value.  I have 16 text boxes on my form all named txtT* where * ranges from 1 to 16.  I want to find the sum of the values within the textboxes using the simplest method possible and I thought I could create a string using a loop and then execute it to get it's value.

This is what I would like to do (if it is possible)...

dim strValue as string
dim x as single

x=1
do while x<17
      strValue = "txtT" & x & ".value"
      sum= sum + ***EXECUTE(strValue)***
      x= x + 1
loop

Thank you!

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
the name of function is Eval()

you can run this function by referencing either Microsoft Scriptting Runtime or Microsoft Access 8.0 Object Library
Top Expert 2006

Commented:
Top Expert 2006

Commented:
to be precise

Public Function Eval (ByVal strExpression As String) As Variant

    Dim objScript As New ScriptControl

    objScript.Language = "VBScript"
    Eval = objScript.Eval(strExpression)
End Function
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
You have equation in your textbox or just value

Commented:
It is not earier to use textbox array

Create one textbox and set index to 0 and copy and create textbox array for 0 to 15
Top Expert 2006

Commented:
typical bruintje is out for the day, misreading the question [bad bad bad bad bad etc.....]
with the array you would

dim i as integer
dim varTextBoxValues as variant


for i = 0 to 15
   varTextBoxValues =  varTextBoxValues + textbox(i).value
next

Commented:
Slightly modified

dim i as integer
dim varTextBoxValues as double

for i = 0 to 15
  varTextBoxValues =  varTextBoxValues + val(textbox(i).value)
next

Commented:
>>typical bruintje is out for the day, misreading the question [bad bad bad bad bad etc.....]


Don't blame yourself too hard, we need you here 8->

Author of the Year 2009

Commented:
Moderator, my recommended disposition is:

    Split points between: bruintje and westbrooknewmedia

DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial