Beginner Question - Data Binding to a TextBox

  • Thread starter Thread starter jimscott77
  • Start date Start date
J

jimscott77

Can someone help with the following problem

TextBox1 is bound to a dataset and shows a value of "5"

I am trying to use that value as follows

Variable1 = Val(TextBox1.Text)

The result that I'd expect is that Variable1 would equal 5.
The result that I get is that Variable1 equals 0

How do I get Variable1 to equal 5?

Thanks,

Jim (the beginner)

I am using Visual Basic in Visual Studio.Net
 
Assuming that you see 5 in the text box at run time.

You could try using

Variable1 = ctype(TextBox1.Text, integer)

This is the .Net casting function
 
Yes, the 5 is visible at run time.

With Variable1 = ctype(TextBox1.Text, integer) I get the
following error msg.

An unhandled exception of type 'System.InvalidCastException' occurred
in microsoft.visualbasic.dll
Additional information: Cast from string "" to type 'Integer' is not
valid.

It seems the value in the text box (5) is not recognized and that
TextBox1.Text = NULL or ""

Does the fact that TextBox1 is bound to a dataset mean that I have to
address it with some index value? (Just a shot in the dark).

Thanks again for your help.
 
Update: I actually have three such values that I am trying to use and
am having the same problem on all 3.

TextBox1.Text shows a value of 5 but has a value of ""
TextBox2.Text shows a value of 18 but has a value of ""
TextBox3.Text shows a value of 24 but has a value of ""

However:

At runtime if I change the value in any one of the textboxes then the
values of all the textboxes are update
When I change the value in TextBox1 to 6 then

TextBox1.Text shows a value of 6 and has a value of 6
TextBox2.Text shows a value of 18 but has a value of 18
TextBox3.Text shows a value of 24 but has a value of 24
(I am testing this by having the values of 3 other textboxes reflect
the values of TextBox1, 2, & 3)
How do I get the values to reflect what is shown without changing one
of the original values?

Thanks again,

Jim (the beginner)
 
jimscott77,

This seems very strange. Are you sure that the textbox with the 5 in it is
really named TextBox1? At design time, click the textbox to select it and be
sure that the name in the Properties window is actually TextBox1.

Kerry Moorman
 
I have verified the names, additionally see my follow-up note here or
my 2nd posting on this topic. Thanks for your feedback. Jim
 
Back
Top