Speed
Unlike. Net, the default in VB6 is to pass arguments by using BYREF, and there seems to be nothing to optimize.
But, actually, if you invoke the API, the code copied from the API browser is forced to use ByVal.
This gives us a chance to optimize. Combined previously written
Use API SendMessage to improve the speed of inserting Vb.combobox Item
I again used the code to test a ByRef, ByVal the difference, the result is very exciting: ByRef is 16 times times higher than ByVal
The code is as follows: The longer the string inserted into the ComboBox, the more it can display the ByRef power.
Option Explicit
Private Declare Function sendmessagebyref Lib "user32" Alias "SendMessageA" (ByRef hWnd as Long, ByRef wmsg as Long, byref WParam as Long, ByRef LParam as any) as long
Private Declare Function sendmessagebyval Lib "user32" Alias "SendMessageA" (ByVal hWnd as Long, ByVal wmsg as Long, ByVal WParam as Long, ByVal LParam as any) as long
Private Declare Function gettickcount Lib "kernel32" () as Long
Private Const cb_addstring = &h143
Private Sub Command1_Click ()
Dim II as Long
Dim T as Long
Dim S as String
Combo1.clear
t = GetTickCount ()
' Use API ByRef
For II = 1 to 10000
s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
' Re-assign the value to change the address
Sendmessagebyref Combo1.hwnd, cb_addstring, 0, s
Next
MsgBox "ByRef" & Gettickcount-t
Combo1.clear
t = GetTickCount ()
' Use API ByVal
For II = 1 to 10000
s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Sendmessagebyval Combo1.hwnd, cb_addstring, 0, s
Next
MsgBox "ByVal" & Gettickcount-t
Combo1.clear
t = GetTickCount ()
' Use ordinary ComboBox Add
For II = 1 to 10000
s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Combo1.additem s
Next
MsgBox "ComboBox Add" & gettickcount-t
End Sub
The API will be changed to BYREF, you can improve speed, of course, not all of the API parameters can be so changed, specifically to see if the API function will be the incoming parameters to modify, or whether you will continue to use the parameters passed in.
This can cause some errors, and some APIs do not allow BYREF to be used. The specific situation has to be analyzed concretely. Of course, you can use Byref entirely.