Alternative code to add control |
Post Reply |
Author | |
chrisABC
Senior Member Joined: 05 June 2008 Status: Offline Points: 258 |
Post Options
Thanks(0)
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
|
|
Bernie
Senior Member Joined: 05 July 2007 Location: Taiwan Status: Offline Points: 109 |
Post Options
Thanks(0)
|
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 |
|
JantjeKeizer
Groupie Joined: 12 February 2008 Status: Offline Points: 70 |
Post Options
Thanks(0)
|
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? |
|
ijwelch
Senior Member Joined: 20 June 2006 Status: Offline Points: 262 |
Post Options
Thanks(0)
|
How about:
CB.Add(xtpControlButton, ID_TEST, "My Caption").ToolTipText = "Press this Button" |
|
chrisABC
Senior Member Joined: 05 June 2008 Status: Offline Points: 258 |
Post Options
Thanks(0)
|
It works! Nice one.
|
|
Chris (Manchester, UK) -- www.abc6.co.uk ---- Using CodeJock ActiveX Suite 13.1.0 with Windows8, VB6 SP6
|
|
JantjeKeizer
Groupie Joined: 12 February 2008 Status: Offline Points: 70 |
Post Options
Thanks(0)
|
Another way if you want to set more properties, but don't want to create another variable would be something like this:
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |