0

I am using an input box. In tat am getting the number as input. When the user presses OK the program is workin. But when I press the cancel button am getting a error message

" Conversion from String "" to 'Integer' type is not valid "

If i press cancel I need the program to end. and also i want to know how to move to other form when i press cancel in input box

0

2 Answers 2

2

Its probably a good idea to use try parse for these situations it handles more cases than empty strings for example non numeric characters characters

Dim number As Integer
Dim result As Boolean = Int32.TryParse(inputBox.Text, number)
if Not result Then
    number = 0
End If     
Sign up to request clarification or add additional context in comments.

Comments

1

If user didn't enter anything in the input box and press cancel, it will be an empty string. Your system won't be able to convert an empty string to integer. Therefore, your program should handle this scenario with code similar to below.

If inputBox.Text = "" Then 
    inputValue = 0
Else
    inputValue = inputBox.Text

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.