Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - Alternative code to add control
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Alternative code to add control

 Post Reply Post Reply
Author
Message
chrisABC View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2008
Status: Offline
Points: 258
Post Options Post Options   Thanks (0) Thanks(0)   Quote chrisABC Quote  Post ReplyReply Direct Link To This Post Topic: Alternative code to add control
    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
Back to Top
Bernie View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 July 2007
Location: Taiwan
Status: Offline
Points: 109
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bernie Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
ijwelch View Drop Down
Senior Member
Senior Member


Joined: 20 June 2006
Status: Offline
Points: 262
Post Options Post Options   Thanks (0) Thanks(0)   Quote ijwelch Quote  Post ReplyReply Direct Link To This Post Posted: 16 June 2008 at 10:30am
How about:

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


Back to Top
chrisABC View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 June 2008
Status: Offline
Points: 258
Post Options Post Options   Thanks (0) Thanks(0)   Quote chrisABC Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
JantjeKeizer View Drop Down
Groupie
Groupie


Joined: 12 February 2008
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote JantjeKeizer Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.219 seconds.