Explanation: The value returned by the InputBox () function is a string. Your statement is Num = InputBox (...), because it has been defined that Num is an integer, so when you enter a number, it will be automatically converted into an integer format. When you press Cancel, InputBox () gets an empty string "",which can't be converted into plastic format, so it prompts a real-time error 13, and the type doesn't match ".
Two: If I click OK without entering any information in the pop-up dialog box, I will get an error ~ ~ "Real-time error 13, type mismatch".
Note: Actually, even if you click OK, because you didn't enter anything, after you click OK, InputBox () will still get an empty string named "",because it can't be converted into plastic format (explain the reference question 1), so it still prompts "Real-time error 13, type mismatch".
Three: Another one is that if I enter a non-number in the information box, I will also prompt "Real-time error 13, type mismatch".
Description: Enter non-numeric things (such as 33R88) repeatedly, and press OK, InputBox () to get an original string, that is, "33R88". Because it cannot be directly converted into plastic format (explain the reference question 1), it still prompts "real-time error 13, type mismatch".
To solve this problem, I usually solve it like this:
Define a St variable and let the input statement assign a value to it. Never go wrong!
Then estimate the corresponding change by judging the value of st:
If st= ",exit. If st is not a number, you will be prompted to re-enter. If st is a number, it will be converted into a digital format and executed.
Generally, a default value is put in the input display box to solve the problem of error when pressing OK without entering anything, so that pressing OK directly is equivalent to entering the default value without giving an error prompt. Like this example, you can put a 3.
The specific procedure can be as follows:
Delete the sentence Num = InputBox ("Please enter the displacement time:" and "displacement time") in the program and replace it with the following lines:
Dim St As String
do
St = InputBox ("Please enter the displacement number:", "displacement number", 3).
If St = "",exit Sub.
If IsNumeric(St), exit Do.
Msgbox "Please enter a number!"
ring
Number = value (St)
Pick up your program later.