Text Value of Textbox

  • Thread starter Thread starter Brian P. Hammer
  • Start date Start date
B

Brian P. Hammer

Hi all,

I have an app that creates about 125 textboxes on a form. The names are stored in a SQL table. In that same table, I have formulas for some of the textboxes to perform simple math operation. My problem is that when the form is created, it puts the formula in the text instead of performing the formula. For example, CInt(Text1.Text) + CInt(Text2.Text) is displayed instead of adding the two textboxes.

Dim strSQL1 As String = "SELECT FieldName, Formula FROM tblFormula WHERE FieldName = " & strFieldName
rsFormula.ActiveConnection = cnn
rsFormula.CursorType = CursorTypeEnum.adOpenStatic
rsFormula.Open(strSQL1)
rsFormula.MoveFirst()
myText(i).Text = rsFormula.Fields("Formula").Value
rsFormula.Close()


Any ideas?
Thanks,
 
What gave you the impression that the TextBox would do the math for you?
Do you expect the following to display "21"?
myTextBox = "12+ 7"

As far as I can see rsFormula.Fields("Formula").Value is a string.
Assigning a string to the Text property of a textbox causes the
textbox to display that exact string. What else should it do?

/claes

----------------------------------------------------------
Hi all,

I have an app that creates about 125 textboxes on a form. The names are
stored in a SQL table. In that same table, I have formulas for some of the
textboxes to perform simple math operation. My problem is that when the
form is created, it puts the formula in the text instead of performing the
formula. For example, CInt(Text1.Text) + CInt(Text2.Text) is displayed
instead of adding the two textboxes.

Dim strSQL1 As String = "SELECT FieldName, Formula FROM tblFormula WHERE
FieldName = " & strFieldName
rsFormula.ActiveConnection = cnn
rsFormula.CursorType = CursorTypeEnum.adOpenStatic
rsFormula.Open(strSQL1)
rsFormula.MoveFirst()
myText(i).Text = rsFormula.Fields("Formula").Value
rsFormula.Close()


Any ideas?
Thanks,
 
Then why if I type me.txtbox1.text = Cint(text2.text) + Cint(text3.text)
does it return math? What am I supposed to use to calculate math? I cannot
use a label because the value has to be user editable if they need to tweak
the value.
 
Thanks Claes. I kind of figured I was going to have to come up with some
other way.

--
Brian P. Hammer
Claes Bergefall said:
Because that's a different thing

me.txtbox1.text = Cint(text2.text) + Cint(text3.text)
is not the same thing as
me.txtbox1.text = "Cint(text2.text) + Cint(text3.text)"

Cint(text2.text) + Cint(text3.text) is an expression
"Cint(text2.text) + Cint(text3.text)" is an object of type string

Methods, properties and functions can only return objects, not
expressions. Expressions in turn returns objects (values)

rsFormula.Fields("Formula").Value returns an object of some type
In your case it returns "Cint(text2.text) + Cint(text3.text)" (note the
" surrounding it) wich is an object of type string. When you assign that
string to the Text property of a textbox it will display that exact string.
It will not treat it as an expression, because that's not what it is

I have no idea how to make your string act as an expression. That's
what compilers do, so you might have some luck with the stuff
in the System.CodeDom namespace or the
System.Runtime.CompilerServices namespace

/claes
 
Back
Top