LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Is this the right way to implement your own VBA Control?

If you want to improve a Control's functionality, how do you do it?

The code below is based on my hunch of how VBA works. Amazingly, it
works. But is it legit?

My UserForm has a TreeView. In Initialize(), I equivalence it to a New
instance of my "ImprovedTreeView" class.

Is that the best, most VBA-native way to do it? Even eliminating one
step would improve things.

My biggest confusion is: In a class module, how do you descend from
another class?

I want CImprovedTreeView to have all the behavior of TreeView, plus my
stuff.

I get around it now by implementing a property of CImprovedTreeView of
the type (TreeView) I want to descend from. But that sure is kluge-a-
delic:

***

‘CLASS MODULE CImprovedTreeView

Option Explicit

Private g_Tree As TreeView

'Sample property...which works fine!

Public Property Get FirstNode() As Node
'Action: Return the topmost node of the tree.
'Note: I was going crazy, because I thought, doesn't .Nodes(1) give
you that? Nein, Dummkopf!

Dim N As Node

'Take any node, ascend to its root, then take the root's first
sibling.
With g_Tree
If .Nodes.Count 0 Then
Set N = .Nodes(1)
While Not (N.Parent Is Nothing)
Set N = N.Parent
Wend
Set FirstNode = N.FirstSibling
End If
End With
End Property

Public Property Set Tree(TV As TreeView)

Set g_Tree = TV
End Property


‘MODULE UserForm1
‘TreeView1 is on this form.

Option Explicit

Private ImprovedTreeView as CImprovedTreeView

Private Sub UserForm_Initialize()
‘Note: Why do I have to get involved with naming two classes (TreeView
and CTreeView)? Can I dispense with one?

Set ImprovedTreeView = New CImprovedTreeView
Set ImprovedTreeView.Tree = TreeView1
End Sub

Private Sub DoSomething
Dim N as Node

Set N = ImprovedTreeView.FirstNode
‘etc.
End Sub

***

Thanks.

***
 
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
How best to integrate/implement this? Ed from AZ Excel Programming 2 December 10th 08 09:06 PM
WNetGetUniversalName - how to implement in VBA? KR Excel Programming 1 March 16th 06 03:48 PM
how to implement xbrl mariano Excel Discussion (Misc queries) 0 January 18th 06 02:00 PM
Do anyone know how to implement the function? minrufeng[_3_] Excel Programming 2 August 12th 05 07:38 PM
How to implement an iRtdServer? Hans Guijt Excel Programming 4 October 24th 04 07:17 AM


All times are GMT +1. The time now is 08:00 AM.

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"