Originally Posted by
Cush
Thanks, still kinda confused though :P Im not big on technical terms like try/catch block and what parsing actually is >_>
Try means exactly what it says, it tries something. Code example coming up! In C# but VB.net will be similar
Code:
try
{
//code to try, if it fails, it is "caught" below :D
}
catch (error)
{
//code when caught, if the code above failed aka produced an error, it appears here. Replace (error) with the error you are trying to catch. This is manual error handling, well, more manual :P You can catch multiple errors and treat them differently.
}
Just imagine Parse really said Convert. All .parse is doing is converting it to another format.
decimal.parse converts to decimal.
integer.parse converts to an integer.
Its kinda hard for me to explain, would it not parse successfully if I tried to convert it to decimal and there were letters in the textbox?
If you attempted to tryparse text -> decimal you'd get a result of "false" and out would have no value.
Im still not clear on why it is used also, I mean when I remove tryparse from all of the buttons, I get a few problems - I get overflow errors when too many numbers are entered, and the program crashes if you press a maths function (+,/,-) when theres nothing in the text box.
As would be expected. You've removed the inbuilt (and ineffective, unless you know it well) error handling.
[quote]
Is the output given from parsing a boolean? The only time the output is used is when converting between signed and unsigned numbers.
I'm confused. Reword this :P I'll type in red whats happening in the relevant bit of code below.
Code:
Private Sub btnSign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSign.Click
Dim txtValue As Decimal
If Decimal.TryParse(txt.Text, txtValue) Then
Ok, this line here is using tryparse, if the value in txt.text can't be converted to a decimal, then it returns false. You hjave no code to execute for "false" so it ends the if and exits the sub.
If the result is true, as in the conversion was successful, then it moves on, the condition was satisfied as tryparse returned true.
If Math.Sign(txtValue) = "-1" Then
txt.Text = Math.Abs(txtValue)
Else
txt.Text = -txt.Text
End If
End If
End Sub