Evaluating a number in a textbox

birdieman

Well-known Member
Joined
Jan 13, 2016
Messages
551
If I wanted to test if the NUMBER in a textbox is greater than 50, which of the following is correct/accurate, or are they the same?

If Val(TextBox5) > 50 Then....

or

If TextBox5.Value > 50 Then ...

If neither are correct to evaluate a NUMBER in a textbox, then what is correct. thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If I wanted to test if the NUMBER in a textbox is greater than 50, which of the following is correct/accurate, or are they the same?

If Val(TextBox5) > 50 Then....

or

If TextBox5.Value > 50 Then ...

If neither are correct to evaluate a NUMBER in a textbox, then what is correct. thanks
I would affix the Value property to that first one as well. Both of those will function the same. In the second one, VB will coerce the text number to a real number (automatically and behind the scene) in order to perform the mathematical comparison.
 
Upvote 0
If all of my textboxes deal with numbers, would the above also apply when I am saving contents (which is always a number) to a spreadsheet, ie, use "textbox5.value" ?

Would I ever refer to a TextBox containing numbers as Textbox5.Text? (If this question has many "depends on" responses, no need to waste your time answering it.)

thanks for the response
 
Upvote 0
If all of my textboxes deal with numbers, would the above also apply when I am saving contents (which is always a number) to a spreadsheet, ie, use "textbox5.value" ?

Would I ever refer to a TextBox containing numbers as Textbox5.Text? (If this question has many "depends on" responses, no need to waste your time answering it.)
The contents of a TextBox is text, never numeric... VB coerces the text number to a real number when you use it in a mathematical operation so that it can complete the mathematical operation. As for the Text property question, the help files for the Text property says this in the Remarks section, "For a TextBox, any value you assign to the Text property is also assigned to the Value property" and, while it does not say so for the Value property explicitly, the reverse appears to be true as well.
 
Upvote 0

Forum statistics

Threads
1,217,435
Messages
6,136,607
Members
450,021
Latest member
Jlopez0320

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top