over/under flow question
-
I basically have three problems here. First I have created a Calculator but it uses error handlers. I have searched to find codes to create a overflow exception code and underflow exception but found no luck. What I want to do is create an overflow and underflow code so that if the interger is over or under the input then it will bypass the following message: "Unhandled exception of type "System.Overflow" occurred in microsoft.visualbasic.dll" And the same for the underflow exception error too. The last problem I need help on is creating another code so that if the user inputs 1.1.1.1 then an error message will occur. The user is only allowed to enter one decimal point and if the user inputs more than one in the text field then I would like an error message to appear. I know how to create an error message but don't know what code to use if there is more than one decimal inputted. I would also like all the codes to use the Try/Catch statements. Can anyone help me? Thanks in advance
-
I basically have three problems here. First I have created a Calculator but it uses error handlers. I have searched to find codes to create a overflow exception code and underflow exception but found no luck. What I want to do is create an overflow and underflow code so that if the interger is over or under the input then it will bypass the following message: "Unhandled exception of type "System.Overflow" occurred in microsoft.visualbasic.dll" And the same for the underflow exception error too. The last problem I need help on is creating another code so that if the user inputs 1.1.1.1 then an error message will occur. The user is only allowed to enter one decimal point and if the user inputs more than one in the text field then I would like an error message to appear. I know how to create an error message but don't know what code to use if there is more than one decimal inputted. I would also like all the codes to use the Try/Catch statements. Can anyone help me? Thanks in advance
justmeTW wrote: What I want to do is create an overflow and underflow code so that if the interger is over or under the input then it will bypass the following message: Use catch statements that target the System.OverflowException class to display a personalized message on overflow errors. justmeTW wrote: if the user inputs 1.1.1.1 then an error message will occur. I would suggest using an extended textobx control that would validate user input instead of using try/catch clauses.
-
justmeTW wrote: What I want to do is create an overflow and underflow code so that if the interger is over or under the input then it will bypass the following message: Use catch statements that target the System.OverflowException class to display a personalized message on overflow errors. justmeTW wrote: if the user inputs 1.1.1.1 then an error message will occur. I would suggest using an extended textobx control that would validate user input instead of using try/catch clauses.
So to use the try/catch for the over/underflow the code should be something like this: Try myAnswer = myNumber1 / myNumber2 MessageBox.Show(msg1, "Invalid format") Catch ex1 as System.OverflowException msg1 = "Error: Invalid Arguement," & vbCrLt _ & ex1.message End Try Is this what I would use to bypass the overflow and underflow error exception? apferreira wrote: I would suggest using an extended textobx control that would validate user input instead of using try/catch clauses. Can you go a little more into depth? And if possible an example code. If I see the code I understand more. Thanks so much for the help
-
So to use the try/catch for the over/underflow the code should be something like this: Try myAnswer = myNumber1 / myNumber2 MessageBox.Show(msg1, "Invalid format") Catch ex1 as System.OverflowException msg1 = "Error: Invalid Arguement," & vbCrLt _ & ex1.message End Try Is this what I would use to bypass the overflow and underflow error exception? apferreira wrote: I would suggest using an extended textobx control that would validate user input instead of using try/catch clauses. Can you go a little more into depth? And if possible an example code. If I see the code I understand more. Thanks so much for the help
The MessageBox.Show method should be inside the catch statament, i.e.
Try var1=number1/number2 Catch e As System.OverflowException MessageBox.Show("Error:Invalid Argument" & e.Message","Invalid format") End Try
As for the extended textbox control that validates user input, I suggest you read the following CodeProject articles: Validating TextBoxControls[^] Validating TextBox[^] And for a more general view on custom control development, I suggest the following MSDN article Developing Custom Windows Controls using Visual Basic NET[^]