Sign in to follow this  
Renegadeandy

[.net] Checking to see if label textbox contents are Integer

Recommended Posts

I want to a run a bit of code , only if the current contents of two textboxes are integers. In C i would just try casting the contents to an int, if it fails, then its not an int, but I dont know how to do this in VB.net Currently I have this : Private Sub NNumberRequired_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NNumberRequired.TextChanged If NUnitCost.Text Then REM CHECK IF CONTENTS OF TEXTBOX IS AN INT CostOfPurchase.Text = NUnitCost.Text * NNumberRequired.Text End If Please help! Cheers Andy

Share this post


Link to post
Share on other sites
I know how to do it in C#, so I will show you that. It should be trivial to figure out how to convert it.


int val = 0;
if( int.TryParse( textBox.Text, out val ) )
{
// val is the string as an integer
}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this