Print Page | Close Window

Alternative code to add control

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=11045
Printed Date: 07 October 2024 at 8:25pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Alternative code to add control
Posted By: chrisABC
Subject: Alternative code to add control
Date Posted: 16 June 2008 at 3:48am
Both of the following seem to work OK

1.    CB.Add xtpControlButton, ID_TEST, "My Caption"
       tmpControl = CB.FindControl(, ID_TEST)
       tmpcontrol.ToolTipText = "Press this Button"


2.    set tmpControl = CB.Add(xtpControlButton, ID_TEST, "My Caption")
       tmpcontrol.ToolTipText = "Press this Button"


Is there any different result?
Is method 2 better (less code and faster operation?)




-------------
Chris (Manchester, UK) -- www.abc6.co.uk ---- Using CodeJock ActiveX Suite 13.1.0 with Windows8, VB6 SP6



Replies:
Posted By: Bernie
Date Posted: 16 June 2008 at 6:46am
Considering efficiency, the second method is better because CPU doesn't need to "look for" the control to assign its tooltiptext.
 
But, variable that stores control info consumes memory.
 
If you want to save memory, use the first method.
If you want to run faster, use the second one.
If your computer is "ALMIGHTY" (for example, 4GB RAM, 4 Cores CPU),
forget it!


-------------
Bernie Ho, Planning Manager + IELTS specialist + part-time programmer
Taiwan, R.O.C


Posted By: JantjeKeizer
Date Posted: 16 June 2008 at 10:09am
Method 2 wont consume any extra amount of memory.
The object exists anyway, and it's only a reference to the object. Method 2 is better. Method 1 simply doesn't make sense. It's like farbicating something then immediatly throw it in the water and then dive into the water to find it again.
Why do all that when the function returns the object you are looking for?


Posted By: ijwelch
Date Posted: 16 June 2008 at 10:30am
How about:

CB.Add(xtpControlButton, ID_TEST, "My Caption").ToolTipText = "Press this Button"




Posted By: chrisABC
Date Posted: 16 June 2008 at 6:23pm
It works!  Nice one.

-------------
Chris (Manchester, UK) -- www.abc6.co.uk ---- Using CodeJock ActiveX Suite 13.1.0 with Windows8, VB6 SP6


Posted By: JantjeKeizer
Date Posted: 17 June 2008 at 3:23am
Another way if you want to set more properties, but don't want to create another variable would be something like this:


With CB.ADd(xtpControlButton,ID_TEST,"My Caption")
.TooltipText = "Press this Button"
.DescriptionText = "This is the description"
.IconID=250
End With



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net