Say from "acceleration VB"

xiaoxiao2021-03-06  43

There is a "accelerated VB" in the previous paragraph NetEase journal. I thought that the shortcomings of most VB programmers, so it is not too arrogant, here is here. In this article, the three ways of majoring procedures, because the original text was mistaken, I just wrote, and the original text has been put, but it is very good, first is the author's friend: if Form1 .WindowState = vbNormal Then MsgBox "window in the normal state" Else If Form1.WindowState = vbMinimized Then MsgBox "window in the minimized state" Else If Form1.WindowState = vbMaximized Then MsgBox "window in the maximized state" End If End Ifnd IF is then modified by the author: with form1 if .windowState = vbnormal kilobox "This window is in the normal state" elseif .windowstate = VBMINIMIMIZED THEN MSGBOX "this window is minimizing status" elseif .windowstate = vbmaximized kilbox " This window is in maximizing the status "end ifnd with) This window is in normal state" case vbmaximized msgbox "this window in normal status" case vbmaximized msgbox "this window in normal status" case vbmaximized msgbox "this window is in the largest State "end if, the author is modified by the best programs, and I will simply analyze the three sections. In fact, the first program and the second program have no essential difference, where the WITH statement does not play the effects - such as a property "form1.picture1.picture.height" uses "with form1.picture1.picture" useful However, there is no use here, VB helps say VB for every "." Time to pay some analysis, the use of With in the second program did not decrease ".", So speed does not speed up, just look Compare neat. The third program is of course a standard usage. In fact, the preferred choice for this problem is "SELECT CASE", which should be a habit, but it is essential to develop good program habits. However, from many people do not use "Select Case", it is very rushing to feel the feeling. I don't want to emphasize programming must be born, but for programming, there is a whole understanding of the language is very important, for class or The use of controls We can slowly check, but for the statement like "Select Case", there must be a sufficient understanding before the programming.

Now I want to rewrite the above procedure, I don't remember that the original author is "form1", but I use "ME", simple and transplant, this habit is also very good, recommended, ok, let's say that the above program can be like this Write: DIM S: S = Array ("Normal", "Minimize", "Maximize") MSGBOX "This window in & S (Me.WindowState) &" Status "may be more strange to this way of writing There will even be resistant to the thoughts, but this is a minimum way of writing. It will not be slower than "select case", because "select case" can determine the string, there are many integrated complex formats (see "SELECT CASE" VB help), is bound to be slower, do not believe you can test, if I am wrong, I will re-recognize a VB. In fact, irregular writing is more than one, let's write one: DIM S as integer: s = me.windowStatemsgbox "This window is in" & switch (s = 0, "normal", s = 1, "Minimize", S = 2, "Maximize") & "Status" In order to make the line short, I use a number instead of the system-defined variable, I am not a big problem, but this is not a good habit, it is likely I will find too many similar places when you look back and upgrade the program. However, if you regret it! Here I use the variable S to get the value of "Me.WindowState" to determine, not only the program is shortened, and the speed is faster, why is this? If you have edited "class module", if you have compiled "Properties", you will know that "Properties" is actually consisting of two functions, a variable is a function, and natural "variable" is fast, in fact I am Here is lesson, this is the search program written for "VBAPI". I used to write this: SUB B2_ONCLICK () DIM I, V, N: V = Trim (T2.Value): n = LEN (V (V) ) IF n> 0 THEN ANSWER.INNNERHTML = "" for i = 0 to Ubound (index) IF INSTR (1, INDEX (I), V, 1) Then answer.innerhtml = answer.innerhtml & _ & index (i) & "" End if Next else msgbox "Please enter a valid search keyword" End ifnd Sub is in use, If the number of items found is not much, this program is also very good, but the number of items will be dead, I have to check all the API names, I have to sleep.

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

New Post(0)