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

CodePudding user response:

reference 1st floor bakw 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
sorry, forgot to explain, I of the application of about 30 text box, is there any faster code to check whether each text box has a value?

CodePudding user response:

refer to the second floor u011143303 response:
Quote: refer to 1st floor bakw 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
sorry, forgot to explain, I of the application of about 30 text box, is there any faster code to check whether each text box has a value?


Use the text control array, in the event of change detection for value

CodePudding user response:

Use the text control array, would have been better

CodePudding user response:

 private sub command1_click () 
OnError Goto Errproc:
Text3. Text=text1. Text + text2. Text
The Exit Sub
Errproc:
MsgBox Err. The Description
End sub

CodePudding user response:

The landlord and not forget issues such as input value is what format, does it include hexadecimal character, contains the decimal point, and so on?

30 text box control array? Or in addition to the 30 text box no other text box?

Any optimization algorithm are related to the specific conditions, the original poster should know,

CodePudding user response:

With custom controls is better, you have what demand as long as change control
  • Related