Multiple formatExeption

hadinatayp

Well-known member
Joined
Feb 8, 2006
Messages
95
Programming Experience
Beginner
i have to validate input for number (integer type) and price (double type),

i would code something like,

------------------------------------------
dim tempNumber as integer
dim tempPrice as double

try

tempNumber=convert.toint32(txtnumber.text)
tempPrice=convert.todouble(txtprice.text)

catch ex as formatException
messagebox.show("Error Number input")
txtnumber.focus()
end try
----------------------------------------

if i enter a string in the Number textbox the try block will catch the exception and display the error message (for the number), same thing will happend if i put a string in price textbox (suppose i enter an integer in the number textbox) (the message will show up stating error in number textbox)

the problem is how make a new exception that catch the double format exception and show the appropriate error message (for the price textbox)

thanks.
 
Don't, throwing exceptions is an expensive process and should be avoided. The Textbox raises a validation event. So you can check the format of the text entered. Then cancel the event and display a messagebox if it doesn't match the fomat you require.
 
Back
Top