Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Collection Class problems

Hi.

I've just trying to make a class, and I have a error, that I need help with.

I have no problem getting data into my collection class, but I have problems
using the functions 'Exists' and 'Item'........... Error 427: Object
required

Can you tell me why ?

Thanks
Flemming



My Class 'clsErrCode' looks like this:
Option Explicit

Private mvCodeID As Variant
Private msName As String
Private mdFreq As Double
Private mdDura As Double


Public Property Let CodeID(ByVal vValue As Variant)
mvCodeID = vValue
End Property
Public Property Get CodeID() As Variant
CodeID = mvCodeID
End Property


Public Property Let Name(ByVal sValue As String)
msName = sValue
End Property
Public Property Get Name() As String
Text = msName
End Property


Public Property Let Frequency(ByVal dValue As Double)
mdFreq = dValue
End Property
Public Property Get Frequency() As Double
Frequency = mdFreq
End Property


Public Property Let Duration(ByVal dValue As Double)
mdDura = dValue
End Property
Public Property Get Duration() As Double
Duration = mdDura
End Property


My collection class 'clsErrCodes' looks like this:
Option Explicit

Private mCol As Collection


' Add
Public Function Add( _
ByVal vntCode As Variant, _
ByVal sErrText As String _
) As clsErrCode

On Error GoTo ErrHandle
Dim objErrCode As clsErrCode

' If Not (Exists(vntCode)) Then
' Tilføjer Code til samlingen
mCol.Add vntCode, CStr(vntCode)

' Sætter Code's Egenskaber
objErrCode.CodeID = vntCode

' Returnerer 'ErrCode' objektet
Set Add = objErrCode
' End If

Set objErrCode = Nothing
Exit Function

ErrHandle:
' 457 - This key already associated with an element of this collection
If Err.Number = 457 Then
Set Add = Nothing
End If
End Function


' Count
Public Property Get Count() As Long
Count = mCol.Count
End Property


' Remove
Public Function Remove(ByVal vntCode As Variant) As Boolean
mCol.Remove vntCode
End Function


' Exists
Public Function Exists(ByVal vntCode As Variant) As Boolean
Dim objErrCode As New clsErrCode
Dim bRetVal As Boolean

bRetVal = False

For Each objErrCode In mCol
If objErrCode.CodeID = vntCode Then
bRetVal = True
Exit For
End If
Next objErrCode

Set objErrCode = Nothing
Exists = bRetVal
End Function


' Clear
Public Sub Clear()
Class_Initialize
End Sub

' Item
Public Function Item(ByVal Index As Variant) As clsErrCode
' This line is inserted using NotePad before import
' It is not visible here after import.
'Attribute Item.VB_UserMemId = 0
Set Item = mCol.Item(Index)
End Function


' NewEnum
Public Function NewEnum() As IUnknown
' Thise two lines is inserted using NotePad before import
' Thy are not visible here after import.
'Attribute NewEnum.VB_UserMemId = -4
'Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = mCol.[_NewEnum]
End Function


' Class
Private Sub Class_Initialize()
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
Set mCol = Nothing
End Sub


Trying to display something with this command:
gobjErrCodes is the global variable of clsErrCodes that have been
filled - the 'Count' works fine.
MsgBox gobjErrCodes.Item(2).CodeID & vbCrLf & _
gobjErrCodes.Item(2).Name




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Collection Class problems

Hi

Succes for me - I made it work :-)

Cheers,
Flemming



"Flemming Dahl" < wrote in message
...
Hi.

I've just trying to make a class, and I have a error, that I need help

with.

I have no problem getting data into my collection class, but I have

problems
using the functions 'Exists' and 'Item'........... Error 427: Object
required

Can you tell me why ?

Thanks
Flemming



My Class 'clsErrCode' looks like this:
Option Explicit

Private mvCodeID As Variant
Private msName As String
Private mdFreq As Double
Private mdDura As Double


Public Property Let CodeID(ByVal vValue As Variant)
mvCodeID = vValue
End Property
Public Property Get CodeID() As Variant
CodeID = mvCodeID
End Property


Public Property Let Name(ByVal sValue As String)
msName = sValue
End Property
Public Property Get Name() As String
Text = msName
End Property


Public Property Let Frequency(ByVal dValue As Double)
mdFreq = dValue
End Property
Public Property Get Frequency() As Double
Frequency = mdFreq
End Property


Public Property Let Duration(ByVal dValue As Double)
mdDura = dValue
End Property
Public Property Get Duration() As Double
Duration = mdDura
End Property


My collection class 'clsErrCodes' looks like this:
Option Explicit

Private mCol As Collection


' Add
Public Function Add( _
ByVal vntCode As Variant, _
ByVal sErrText As String _
) As clsErrCode

On Error GoTo ErrHandle
Dim objErrCode As clsErrCode

' If Not (Exists(vntCode)) Then
' Tilføjer Code til samlingen
mCol.Add vntCode, CStr(vntCode)

' Sætter Code's Egenskaber
objErrCode.CodeID = vntCode

' Returnerer 'ErrCode' objektet
Set Add = objErrCode
' End If

Set objErrCode = Nothing
Exit Function

ErrHandle:
' 457 - This key already associated with an element of this collection
If Err.Number = 457 Then
Set Add = Nothing
End If
End Function


' Count
Public Property Get Count() As Long
Count = mCol.Count
End Property


' Remove
Public Function Remove(ByVal vntCode As Variant) As Boolean
mCol.Remove vntCode
End Function


' Exists
Public Function Exists(ByVal vntCode As Variant) As Boolean
Dim objErrCode As New clsErrCode
Dim bRetVal As Boolean

bRetVal = False

For Each objErrCode In mCol
If objErrCode.CodeID = vntCode Then
bRetVal = True
Exit For
End If
Next objErrCode

Set objErrCode = Nothing
Exists = bRetVal
End Function


' Clear
Public Sub Clear()
Class_Initialize
End Sub

' Item
Public Function Item(ByVal Index As Variant) As clsErrCode
' This line is inserted using NotePad before import
' It is not visible here after import.
'Attribute Item.VB_UserMemId = 0
Set Item = mCol.Item(Index)
End Function


' NewEnum
Public Function NewEnum() As IUnknown
' Thise two lines is inserted using NotePad before import
' Thy are not visible here after import.
'Attribute NewEnum.VB_UserMemId = -4
'Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = mCol.[_NewEnum]
End Function


' Class
Private Sub Class_Initialize()
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
Set mCol = Nothing
End Sub


Trying to display something with this command:
gobjErrCodes is the global variable of clsErrCodes that have been
filled - the 'Count' works fine.
MsgBox gobjErrCodes.Item(2).CodeID & vbCrLf & _
gobjErrCodes.Item(2).Name






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Collection Class problems

Fleming,

This was a complex one (must admit, your code looks overly complex for an
errors collection). I had it down to look at tomorrow.

Can you post you solution? If I do look at it I will post my suggestion.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Flemming Dahl" wrote in message
...
Hi

Succes for me - I made it work :-)

Cheers,
Flemming



"Flemming Dahl" < wrote in message
...
Hi.

I've just trying to make a class, and I have a error, that I need help

with.

I have no problem getting data into my collection class, but I have

problems
using the functions 'Exists' and 'Item'........... Error 427: Object
required

Can you tell me why ?

Thanks
Flemming



My Class 'clsErrCode' looks like this:
Option Explicit

Private mvCodeID As Variant
Private msName As String
Private mdFreq As Double
Private mdDura As Double


Public Property Let CodeID(ByVal vValue As Variant)
mvCodeID = vValue
End Property
Public Property Get CodeID() As Variant
CodeID = mvCodeID
End Property


Public Property Let Name(ByVal sValue As String)
msName = sValue
End Property
Public Property Get Name() As String
Text = msName
End Property


Public Property Let Frequency(ByVal dValue As Double)
mdFreq = dValue
End Property
Public Property Get Frequency() As Double
Frequency = mdFreq
End Property


Public Property Let Duration(ByVal dValue As Double)
mdDura = dValue
End Property
Public Property Get Duration() As Double
Duration = mdDura
End Property


My collection class 'clsErrCodes' looks like this:
Option Explicit

Private mCol As Collection


' Add
Public Function Add( _
ByVal vntCode As Variant, _
ByVal sErrText As String _
) As clsErrCode

On Error GoTo ErrHandle
Dim objErrCode As clsErrCode

' If Not (Exists(vntCode)) Then
' Tilføjer Code til samlingen
mCol.Add vntCode, CStr(vntCode)

' Sætter Code's Egenskaber
objErrCode.CodeID = vntCode

' Returnerer 'ErrCode' objektet
Set Add = objErrCode
' End If

Set objErrCode = Nothing
Exit Function

ErrHandle:
' 457 - This key already associated with an element of this

collection
If Err.Number = 457 Then
Set Add = Nothing
End If
End Function


' Count
Public Property Get Count() As Long
Count = mCol.Count
End Property


' Remove
Public Function Remove(ByVal vntCode As Variant) As Boolean
mCol.Remove vntCode
End Function


' Exists
Public Function Exists(ByVal vntCode As Variant) As Boolean
Dim objErrCode As New clsErrCode
Dim bRetVal As Boolean

bRetVal = False

For Each objErrCode In mCol
If objErrCode.CodeID = vntCode Then
bRetVal = True
Exit For
End If
Next objErrCode

Set objErrCode = Nothing
Exists = bRetVal
End Function


' Clear
Public Sub Clear()
Class_Initialize
End Sub

' Item
Public Function Item(ByVal Index As Variant) As clsErrCode
' This line is inserted using NotePad before import
' It is not visible here after import.
'Attribute Item.VB_UserMemId = 0
Set Item = mCol.Item(Index)
End Function


' NewEnum
Public Function NewEnum() As IUnknown
' Thise two lines is inserted using NotePad before import
' Thy are not visible here after import.
'Attribute NewEnum.VB_UserMemId = -4
'Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = mCol.[_NewEnum]
End Function


' Class
Private Sub Class_Initialize()
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
Set mCol = Nothing
End Sub


Trying to display something with this command:
gobjErrCodes is the global variable of clsErrCodes that have been
filled - the 'Count' works fine.
MsgBox gobjErrCodes.Item(2).CodeID & vbCrLf & _
gobjErrCodes.Item(2).Name








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Collection Class problems

Bob, He wasn't adding the instance of the of the object to the
collection.

Flemming, Are you aware your allows you to short cut the Item method
in the traditional manner i.e.

MsgBox gobjErrCodes(2).CodeID & vbCrLf & _
gobjErrCodes(2).Name

--

"Bob Phillips" wrote in message ...
Fleming,

This was a complex one (must admit, your code looks overly complex for an
errors collection). I had it down to look at tomorrow.

Can you post you solution? If I do look at it I will post my suggestion.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Flemming Dahl" wrote in message
...
Hi

Succes for me - I made it work :-)

Cheers,
Flemming



"Flemming Dahl" < wrote in message
...
Hi.

I've just trying to make a class, and I have a error, that I need help

with.

I have no problem getting data into my collection class, but I have

problems
using the functions 'Exists' and 'Item'........... Error 427: Object
required

Can you tell me why ?

Thanks
Flemming



My Class 'clsErrCode' looks like this:
Option Explicit

Private mvCodeID As Variant
Private msName As String
Private mdFreq As Double
Private mdDura As Double


Public Property Let CodeID(ByVal vValue As Variant)
mvCodeID = vValue
End Property
Public Property Get CodeID() As Variant
CodeID = mvCodeID
End Property


Public Property Let Name(ByVal sValue As String)
msName = sValue
End Property
Public Property Get Name() As String
Text = msName
End Property


Public Property Let Frequency(ByVal dValue As Double)
mdFreq = dValue
End Property
Public Property Get Frequency() As Double
Frequency = mdFreq
End Property


Public Property Let Duration(ByVal dValue As Double)
mdDura = dValue
End Property
Public Property Get Duration() As Double
Duration = mdDura
End Property


My collection class 'clsErrCodes' looks like this:
Option Explicit

Private mCol As Collection


' Add
Public Function Add( _
ByVal vntCode As Variant, _
ByVal sErrText As String _
) As clsErrCode

On Error GoTo ErrHandle
Dim objErrCode As clsErrCode

' If Not (Exists(vntCode)) Then
' Tilføjer Code til samlingen
mCol.Add vntCode, CStr(vntCode)

' Sætter Code's Egenskaber
objErrCode.CodeID = vntCode

' Returnerer 'ErrCode' objektet
Set Add = objErrCode
' End If

Set objErrCode = Nothing
Exit Function

ErrHandle:
' 457 - This key already associated with an element of this

collection
If Err.Number = 457 Then
Set Add = Nothing
End If
End Function


' Count
Public Property Get Count() As Long
Count = mCol.Count
End Property


' Remove
Public Function Remove(ByVal vntCode As Variant) As Boolean
mCol.Remove vntCode
End Function


' Exists
Public Function Exists(ByVal vntCode As Variant) As Boolean
Dim objErrCode As New clsErrCode
Dim bRetVal As Boolean

bRetVal = False

For Each objErrCode In mCol
If objErrCode.CodeID = vntCode Then
bRetVal = True
Exit For
End If
Next objErrCode

Set objErrCode = Nothing
Exists = bRetVal
End Function


' Clear
Public Sub Clear()
Class_Initialize
End Sub

' Item
Public Function Item(ByVal Index As Variant) As clsErrCode
' This line is inserted using NotePad before import
' It is not visible here after import.
'Attribute Item.VB_UserMemId = 0
Set Item = mCol.Item(Index)
End Function


' NewEnum
Public Function NewEnum() As IUnknown
' Thise two lines is inserted using NotePad before import
' Thy are not visible here after import.
'Attribute NewEnum.VB_UserMemId = -4
'Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = mCol.[_NewEnum]
End Function


' Class
Private Sub Class_Initialize()
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
Set mCol = Nothing
End Sub


Trying to display something with this command:
gobjErrCodes is the global variable of clsErrCodes that have been
filled - the 'Count' works fine.
MsgBox gobjErrCodes.Item(2).CodeID & vbCrLf & _
gobjErrCodes.Item(2).Name






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Collection Class problems

Hi

Thanks for looking - but don't waste you time it is solved.

In the Add function the line
Dim objErrCode As clsErrCode
should be
Dim objErrCode As New clsErrCode

I belive there was some other small things, but the New part is the main
part.

Cheers,
Flemming


Reply
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
template for dvd collection David Excel Discussion (Misc queries) 2 April 26th 10 11:35 PM
data collection driller Excel Discussion (Misc queries) 1 October 13th 09 01:04 AM
help with data collection! brandon roland[_2_] New Users to Excel 1 August 8th 07 10:09 PM
RaiseEvent from a class contained in a 2nd class collection? Andrew[_16_] Excel Programming 2 January 6th 04 04:22 PM
For/Each iteration for collection class Stelio Excel Programming 1 October 31st 03 12:46 PM


All times are GMT +1. The time now is 08:50 PM.

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"