Rabu, 14 September 2011

Re: [MS_AccessPros] Some code I can't decipher

 

Lee,

On page 74-75 the code is found. The subheading is Disadvantages of Collection Classes.

I do not have the time right now to type the text. maybe a little later in the afternoon.

 
Jim Wagner
________________________________

________________________________
From: Lee <leevt99@yahoo.com>
To: MS_Access_Professionals@yahoogroups.com
Sent: Wednesday, September 14, 2011 8:56 AM
Subject: [MS_AccessPros] Some code I can't decipher

 
Hi,
I have the Access 2002 Developers Handbook (well I have the software for the book, no idea what happened to the book itself), and was trying to learn more about classes and how to use them. I ran across some strange looking code in one of the sample files and I can't figure out what it does, or why it's even there. It's part of a custom collection class.

Public Function NewEnum() As IUnknown
' Enumeration function for the collection
Set NewEnum = mcolLines.[_NewEnum]
End Function

There is no enumeration defined anywhere, but mcolLines is declared as a private class collection variable. This routine is also not called anywhere in the sample file. I pasted the entire class below.

what is "IUnknown"? Or is that sort of redundant to ask? O.o

Why are the brackets around [_NewEnum] and how does the underscore function?

While I'm at it does anyone have an vba specific class resources?

Thanks
-Lee

' From Access 2002 Desktop Developer's Handbook
' by Litwin, Getz, and Gunderloy. (Sybex)
' Copyright 2001. All Rights Reserved.

Option Compare Database
Option Explicit

' Private collection to store Lines
Private mcolLines As Collection

Public Function NewEnum() As IUnknown
' Enumeration function for the collection
Set NewEnum = mcolLines.[_NewEnum]
End Function

Private Sub Class_Initialize()
' Instantiate the Collection object
Set mcolLines = New Collection
End Sub

Public Sub Add(ByVal strText As String, Optional ByVal varBefore As Variant)
' Declare new Line object
Dim objLine As New Line

' Set Text property to passed string
objLine.Text = strText
' Add to private collection, using object's
' ID property as unique index
mcolLines.Add objLine, objLine.ID, varBefore
End Sub

Public Sub Remove(ByVal varID As Variant)
' Call Remove method of private collection object
mcolLines.Remove varID
End Sub

Public Function Item(ByVal varID As Variant) As Line
' Set return value of property to item within
' the private collection object specified by
' the passed index value (Note the return type!)
Set Item = mcolLines(varID)
End Function

Property Get Count() As Long
' Return Count property of private collection
Count = mcolLines.Count
End Property

Property Let Changed(ByVal fChanged As Boolean)
Dim objLine As Line

' Set Changed property of each Line to fChanged
For Each objLine In mcolLines
objLine.Changed = fChanged
Next
End Property

Property Get Changed() As Boolean
Dim objLine As Line

' Loop through all Line objects in collection--
' if any Changed property is True then the
' Changed property of the collection is True
For Each objLine In mcolLines
If objLine.Changed Then
Changed = True
Exit For
End If
Next
End Property

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity:
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.


A bad score is 598. A bad idea is not checking yours, at freecreditscore.com.
.

__,_._,___

Tidak ada komentar:

Posting Komentar