That
public bool IsNumeric is the method.
A method is a function inside a class, you call a method in order to do something.
It's used so that you can do something dynamic, or use it over and over again, saving you lot's of time in writing code and making it more efficient.
Where you have the IsNumeric method is fine right now, it needs to be inside of the class braces and not inside any other methods...
Code: Select all
class
{
method
{
// do stuff
}
method
{
// do stuff
}
}
Now you need to make a button event handler.
The easiest way to do this is just by double clicking on the button in the Design view.
This will auto-generate the Event Handler code for you and take you right to the method created.
You should defiantly see how it works someday so that you can get an understanding at what it is doing.
You can paste in your other code within that new button click method you just created...
Code: Select all
if(IsNumeric(TextBox1.Text) == true)
{
// your temp convert code goes here
}
else
{
// your message window code goes here
}
This code calls the
IsNumeric method and is passing in a string(text).
The method is of type
bool (boolean) meaning it returns a true or false depending on what it says in the method.
So you can assume by the name
IsNumeric it returns
true if what you wrote was a number, and
false if it wasn't a number.
Everything within the first loop with "your temp convert code goes here" is what you write when you get true.
And the else is for anything other than true, which can only be false (in this case of a boolean).
The method you wrote in is advanced for just beginners however, you might want to either forget that or move on (if you even can) unless you know what Try...Catch is...
Hope this helps.