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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
to be precise
Public Function Eval (ByVal strExpression As String) As Variant
Dim objScript As New ScriptControl
objScript.Language = "VBScript"
Eval = objScript.Eval(strExpressi on)
End Function
Public Function Eval (ByVal strExpression As String) As Variant
Dim objScript As New ScriptControl
objScript.Language = "VBScript"
Eval = objScript.Eval(strExpressi
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Slightly modified
dim i as integer
dim varTextBoxValues as double
for i = 0 to 15
varTextBoxValues = varTextBoxValues + val(textbox(i).value)
next
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->
Don't blame yourself too hard, we need you here 8->
Moderator, my recommended disposition is:
Split points between: bruintje and westbrooknewmedia
DanRollins -- EE database cleanup volunteer
Split points between: bruintje and westbrooknewmedia
DanRollins -- EE database cleanup volunteer
http://www.4guysfromrolla.com/webtech/030300-1.shtml