The so-called robust system means that the input that does not comply with the specification requirements can be determined and the processing method can be reasonable. Software Robustness is a vague concept, but it is a very important external software measurement standard. The robustness of software design directly reflects the level of analysis design and coding personnel. That is, the so-called high-handwriting program is not easy to die. Although I am not a master, I still have a deep understanding when I fail to enter the text box from the data room charging system I just created.
- 1. Log On with the user name.
Since it is a login, you must use the database query, but the query statement has an error, not only the absence of data, but the direct consequence is that the system reports an error, it cannot be used before you log on to your system. Therefore, programmers should think of all possible situations in advance to ensure the normal use of the software, that is, the fault tolerance of the software is better, and the robustness is stronger.
In combination with SQL query statements, if "'" and "=" are avoided, these symbols will directly cause incorrect statements and prompt error messages. It can be implemented as follows:
Private sub txtusername_keypress (keyascii as integer) If keyascii = 39 or keyascii = 61 Then keyascii = 0 msgbox "do not enter invalid characters", vbokonly + vbexclamation, "warning" End ifend sub
I don't know whether it is found. This ensures that errors are avoided during input. However, in case of right-click and paste, it is not just a stop.
The improvements are as follows:
Private Sub txtUserName_KeyPress(KeyAscii As Integer) Dim s As String Dim i As Integer For i = 1 To Len(txtUserName.Text) s = Mid(txtUserName.Text, i, 1) If s Like "'" Or s Like "=" Then txtUserName = Replace(txtUserName.Text, s, "") End If Nextend sub
However, this is not foolproof. Many people like to use the trim () function when using text in text boxes for Content Query. Spaces appear during data transmission. In addition to a bug, a bug is added. If a space is used during registration and the data storage type is varchar, there may be no matching content. The solution is to have a unified specification for storage and query: either the user name cannot enter a space at the beginning or end, so that trim () can continue (), however, this seems to be in conflict with the user's good experience. In addition, trim is not required. Remember to use varchar as the data storage type. If char is used, spaces are automatically added if the number of characters is not defined, A bug occurs.
In addition to the basic limits of the user name, you must also consider not to enter Chinese characters. Generally, they are uppercase/lowercase letters (case-sensitive), numbers, and some special characters.
However, there must be a limit on the number of digits, which is a common error. The data type is set to 7 bits, but the password is entered to 10 bits, so it is strange that no bug occurs. We just need to make reminders and make perfect restrictions.
Robust software must undergo any abnormal operations.
When I enter the amount, I want to limit it to only numbers at first. However, the amount of money cannot all be integers. to be strong, it is not worth the candle if you sacrifice a good user experience, therefore, this decimal point is required.
But how can we limit it? Enter only one digit after the decimal point.
Method 1:
Private Sub txtCash_KeyPress(KeyAscii As Integer) Dim s As String s = InStr(txtCash, ".") If s And Len(Mid(txtCash, s + 1)) > 0 Then KeyAscii = 0End Sub
Method 2:
Private Sub txtCash_Change() Dim S As String Dim x() As String If (IsNumeric(txtCash.Text)) Then x = Split(txtCash.Text, ".") If (UBound(x) >= 1) Then If (Len(x(UBound(x))) > 1) Then txtCash.Text = S txtCash.SelStart = Len(txtCash.Text) End If End If End If S = txtCash.TextEnd Sub
These two are what I am looking for. Although the functions are basically implemented, I cannot help testing them. Method 1 cannot be modified or input again, because the keyboard is disabled directly. Method 2 is fine-tuned, but it cannot be limited if two funny points are entered. When processing the decimal point, consider moving the mouse and modifying the integer part.
Improved code:
Private sub txtcash_change () dim s as string dim I as integer dim intstart as integer dim intpos as integer 'restrict the input number and decimal point for I = 1 to Len (txtcash. text) S = mid (txtcash. text, I, 1) If s like "[! 0-9] "And not s like ". "Then txtcash. TEXT = Replace (txtcash. text, S, "") end if next I 'specifies the number of digits intpos = instr (txtcash ,". ") intstart = txtcash. selstart if intpos> = 1 then txtcash = left (txtcash, intpos + 1) If intstart> Len (txtcash) Then txtcash. selstart = Len (txtcash) else txtcash. selstart = intstart end if end ifend sub
The robustness of the software is our pursuit. At the same time, we cannot caster the function to reduce the error rate. After all, the software is designed to show users, always thinking about serving the people, and the more humane the software can be sold out. Therefore, we need to think about it all the time and eliminate bugs one by one.