Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Shortening code

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
--


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
shortening code by defining variables using an array? broro183[_2_] Excel Programming 2 March 17th 08 08:30 AM
Multiple Criteria - Shortening Code T De Villiers[_63_] Excel Programming 6 July 29th 06 04:55 PM
Shortening a Macro Paul Sheppard[_16_] Excel Programming 4 June 24th 06 06:49 AM
shortening a forumula Mike_sharp Excel Discussion (Misc queries) 4 May 4th 05 04:54 PM
Help with shortening/cleaning some code please roy Excel Programming 3 June 3rd 04 11:49 PM


All times are GMT +1. The time now is 02:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"