By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,747 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,747 IT Pros & Developers. It's quick & easy.

Beginner Question - Data Binding to a TextBox

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies

P: n/a
Try Variable1 = TextBox1.Text

"jimscott77" <ji********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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

Nov 21 '05 #2

P: n/a
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

--
Weeims
"jimscott77" wrote:
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

Nov 21 '05 #3

P: n/a
as TEXT the result is ""
as VAL the result is 0

Nov 21 '05 #4

P: n/a
as TEXT the result is ""
as VAL the result is 0

Nov 21 '05 #5

P: n/a
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.

Nov 21 '05 #6

P: n/a
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)

Nov 21 '05 #7

P: n/a
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
"jimscott77" wrote:
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.

Nov 21 '05 #8

P: n/a
I have verified the names, additionally see my follow-up note here or
my 2nd posting on this topic. Thanks for your feedback. Jim

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.