In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In today's class, I told the students about the procedure call in access2010. All the access2010 materials I have seen in my impression mentioned that the procedure call call can be omitted. But there are problems in class!
I. situational reproduction
One of the roles in the explanation process: it can reduce the repetition of code and improve the efficiency of sharing. The following code is used:
Private Sub numSort () 'generates 20 integer random numbers between [0100] Dim n (1 To 20) As Integer Dim i As Integer For i = 1 To 20 Randomize n (I) = Rnd () * 101 Next' print random number Dim outString As String outString = "pre-sorting random number: For I = 1 To 20 outString = outString & Str (n (I)) & "" Next Debug.Print outString 'sort Dim temp As Integer Dim j As Integer For i = 1 To 20 For j = I To 20 If (n (I) > n (j)) Then temp = n (I) n (I) = n (j) n (j) = temp End If Next Next OutString = "Random number after sorting:" For I = 1 To 20 outString = outString & Str (n (I)) & "" Next Debug.Print outStringEnd Sub
The purpose of the example is to generate 20 random numbers to be stored in the array, print them out, sort the 20 random numbers from small to large, and then print them out.
This uses two array prints, and the two pieces of code have something in common and can be refined into a process to reduce code and improve code reuse. So I began to modify the code for the students in class. I thought it was a simple thing, but I didn't verify it beforehand, but I laughed. . @). The modified code is as follows:
Private Sub numSort () 'generates an integer random number between 20 [0100] Dim n (1 To 20) As Integer Dim i As Integer For i = 1 To 20 Randomize n (I) = Rnd () * 101 Next' print random number printArr ("random number before sorting:" N) 'sort Dim temp As Integer Dim j As Integer For i = 1 To 20 For j = I To 20 If (n (I) > n (j)) Then temp = n (I) n (I) = n (j) n (j) = temp End If Next Next' Random number End SubPrivate Sub printArr (s As String) after sorting K () As Integer) Dim outString As String outString = s Dim i As Integer For i = LBound (k) To UBound (k) outString = outString & Str (k (I)) & "" Next Debug.Print outStringEnd Sub
When a printArr procedure is defined and a call without call is used when calling, a tragic thing happens, and the following hint is given:
Obviously there is something wrong with the statement printArr ("Random number before sorting:", n). But there is no problem in grammar (alas. This is the consequence of lax scholarship. Remember, remember that you will no longer be a model). Later, I tried to add call to it and changed it to:
Call printArr ("Random number before sorting:", n)
Problem solved!
II. Summary of problems
After that, I tried it through a few examples. Found:
If the parameters of the procedure contain the parameters of the array, call must add the
Otherwise, call can be omitted.
III. Experience and lessons
As a teacher, when imparting knowledge to students, they must be careful to verify, be cautious, be cautious, verify, re-verify, otherwise it is easy to mislead people's children. Empiricism is not desirable, you must bear in mind
In addition: in order to make the code more portable and more general, the above code can be optimized to (using symbolic constants and using lbound and ubound system functions) Option Compare DatabasePrivate Const ARR_LOW = 1 'array superscript Private Const ARR_UPP = 20' array subscript
Private Sub numSort ()
Dim n (ARR_LOW To ARR_UPP) As Integer
Dim i As Integer
For I = LBound (n) To UBound (n)
Randomize
N (I) = Rnd () * 101
Next
'print a random number before sorting
Call printArr ("Random number before sorting:", n)
Dim temp As IntegerDim j As IntegerFor i = LBound (n) To UBound (n) For j = i To UBound (n) If (n (I) > n (j)) Then temp = n (I) n (I) = n (j) n (j) = temp End If NextNext' Random number Call printArr ("Random number after sorting:", n)
End Sub
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.