Some ideas about algorithms

zhaozj2021-02-08  266

Some ideas about algorithms

The algorithm is a programmed soul. Unborn, there is no algorithm that is a high level of program. The shape of the form involves algorithm; the control itself and many of the relationships with other controls need to be calculated; the string lookup, interception, and replacement are inseparable from it ... in short, from a small to a button place, big arrival ... (Where? I don't know), there is no correlation with the algorithm. Algorithms or very simple, or complicated. Everything starts with simplicity, this is a shortcut. This article will indicate where the learning algorithm will begin with the simplest algorithm. Sometimes simple things will make us make a complicated. For example: calculate A of the b, some people do this: Dim A as single, Total As Single, B as integra = text1.text: b = text2.text: Total = 1do while b <> 0total = Total * AB = B - 1LOOPText3.text = Total Even this: private sub command1_click () Dim A As Single, Total AS Singledim B AS Integer, N as Integer

A = text1.texttotal = text1.textb = text2.text

Select Case Bcase 0Total = 1Case IS <0msGBox "Illegal Data", Vbokonly, "Error" Text3.Text = "" EXIT SUBCASE ELSEfor N = 1 to B - 1Total = Total * Anextend SelectText3.Text = Totalend Sub

In fact, if you know that there is an operator "^" specifically calculated such a problem in VB, it will be simple and reliable. Try: DIM A As Double, B AS Integer, c as doublea = text1.text: b = text2.text = A ^ bText3.text = C, for example, VB programming park has recently had an article about flip strings, discussion Using recursive principle, the function is prepared, the algorithm is very accurate, very interesting (recommended serious research): Function ReverseString (revstr as string) AS STRINGDIM DOREVERSE AS LongreveString = "" "" "" "for doreverse = len (revstr) to 1 Step -1Reverstring = ReverseString & Mid $ (REVSTR, DOREVERS, 1) NEXTEND FUNCTION

However, if we use VB's internal functions Strreverse, it is more convenient to say: text2.text = strreverse (text1.text) Looks on the above example, what conclusions you have? Ha, must learn the algorithm, first learn to learn VB operators and internal functions! Eating these things is always wrong, it is only a bitter bit of hardships in the future, look back, wow, VB itself has long been! Of course, I don't have any benefits, I can exercise at least. Just in the era of rapid development today, if it is not for practice, it is best not to take too much detour. I said something wrong, please take an ax!

转载请注明原文地址:https://www.9cbs.com/read-3355.html

New Post(0)