Home |
Search |
Today's Posts |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Garry
"GS" wrote in message ... IanC was thinking very hard : Hi Martin However you should be aware that the code below is *not* functionally equivalent to the code that you posted. It simplifies to: Me.CommandButton1.Enable = Me.ComboBox6.MatchFound Yes, I just discovered that! You could write it as the logical AND of all the terms on the right hand side and that might well be faster on some compilers and CPUs. I would not like to bet on whether or not it is with VBA. The length of time it takes is imperceptible. If there was an equivalent to Debug.Print Now() which returned fractions of a second I could put a figure on it, but to the human eye it's effectively instantaneous. With Me .CommandButton1.Enable = (.ComboBox1.MatchFound) And (.Combobox2.MatchFound) And (...etc End With Would work as intended. Indeed it does. As there's no detectable difference between the speed of this routine and your nested if solution, I'm sticking with this option on the basis that it's less characters and ultimately a smaller file size. And so makes it more efficient code, no? What makes it so is the 'dot Not necessarily in every case. An instruction may be more characters than another but still quicker to execute. That said, in this case the time involved is minimal so the absolute time is irrelevant. processing' is minimal. 'Dot processing' requires resources for each dot ref, which in this case is reintiating the ref to the form object (Me) in every iteration where it's used. So Martin's suggestion is more efficient in that the object ref (and thus reinitialization of that ref) to CommandButton1 is only made once instead of six times. Though, I would write his suggestion this way for clarity and readability: With Me .CommandButton1.Enabled = _ (.ComboBox1.MatchFound) And _ (.ComboBox2.MatchFound) And _ (.ComboBox3.MatchFound) And _ (.ComboBox4.MatchFound) And _ (.ComboBox5.MatchFound) And _ (.ComboBox6.MatchFound) End With Already did this. As you say it's much easier to read and I shortened it even more by removing the parentheses. -- Ian -- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
shortening code by defining variables using an array? | Excel Programming | |||
Multiple Criteria - Shortening Code | Excel Programming | |||
Shortening a Macro | Excel Programming | |||
shortening a forumula | Excel Discussion (Misc queries) | |||
Help with shortening/cleaning some code please | Excel Programming |