Home > Software engineering > VB program, when there are no content of the text, how not to report errors.
VB program, when there are no content of the text, how not to report errors.
Time:10-11
Simple example shows that, assuming that the program is a calculator. Private sub command1_click () Text3. Text=text1. Text + text2. Text End sub When text1 or text2 did not fill in the number and click command1, how the popup msgbox, prompted for Numbers, Will, of course, the above procedure blank text by default value is 0 and continued operation, my program is more complex, each text box must demand has value to operation, once has the blank text box, would prompt "real-time error 13 types do not match",
CodePudding user response:
You want to check every text using isnumeric function, and calculated the type conversion is done first, best cint CDBL such as
Private sub command1_click () If isnumeric (text1. Text) and isnumeric (text2. Text) then Text3. Text=CSTR (CDBL (text1. Text) + CDBL (text2. Text)) The else 'indicates a different text content in the input box, or empty End the if End sub