Link to home
Start Free TrialLog in
Avatar of AlisonP
AlisonP

asked on

Executing a the value of a string variable

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!

ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
You have equation in your textbox or just value
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
typical bruintje is out for the day, misreading the question [bad bad bad bad bad etc.....]
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Slightly modified

dim i as integer
dim varTextBoxValues as double

for i = 0 to 15
  varTextBoxValues =  varTextBoxValues + val(textbox(i).value)
next
>>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->

Avatar of DanRollins
Moderator, my recommended disposition is:

    Split points between: bruintje and westbrooknewmedia

DanRollins -- EE database cleanup volunteer