Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Class Building


Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2003, 04:16 AM
Dan Foord
Guest
 
Posts: n/a
Default Class Building


Has anyone come across this problem with Class

I have a class and I am trying to add "things" (not sure of the technical term!) to it.

Anyway, on running this piece of code in a class module (this has all been built with the VB6 class builder):

Public Property Let Expiry(ByVal vData As Date)
'used when assigning a value to the property, on the left side of an assignment.

'Syntax: X.ExpiryDate = 5
mvarExpiry = vData
End Property

Works fine...
however when adding it to the class:

Public Function Add(NI_Number As String, Expiry As Date) As TStaffJobReq
'create a new object
Dim objNewMember As TStaffJobReq
Set objNewMember = New TStaffJobReq


'set the properties passed into the method
objNewMember.NI_Number = NI_Number
objNewMember.Expiry = Expiry
etc.

objNewMember.Expiry won't take the value of Expiry!
Why not
It works 100% fine for the NI_Number above.

The only difference is that Expiry is taking its value from a value that the user is inputting (everything is dimmed as Date and it is a date combo box, a colleague has double checked this with me!)

What is going on?
Won't classes except dates or boolean (same this is happening with a boolean I am trying to use....)

Many thanks

Dan

Last edited by Dan Foord; 01-13-2003 at 04:22 AM.
Reply With Quote
  #2  
Old 01-13-2003, 04:48 AM
Dutch-O
Guest
 
Posts: n/a
Default

Hi Dan,

Classes and collections do accept booleans and dates. It is hard to see what the problem is. Maybe you can upload your code so we can see better what you do. Out the top of my head I don't see what is wrong.
Reply With Quote
  #3  
Old 01-13-2003, 05:07 AM
Dan Foord
Guest
 
Posts: n/a
Default

Thanks Dutch
I have copied in the code
I no idea what is going on....

I'm not sure this code really adds anything to my first post.
It is quite strange.

My colleague's suggest on Friday was re-boot!
Unfortunately its still here this morning.

The values of Expiry and IsPref are passed using the following code:
Code:
aJobReq.StaffJobReqList.Add S_NI_Number(Val(lstStaff.ItemData(lstStaff.ListIndex))), dExpiry, bPref, "Add" 'Added to the list, NI_No, expiry date, is pref, add or del. The class modules look like: 'TStaffJobReqList 'local variable to hold collection Private mCol As Collection 'FUNCTION CALLED FROM ABOVE CODE Public Function Add(NI_Number As String, Expiry As Date, IsPref As Boolean, Status As String) As TStaffJobReq 'create a new object Dim objNewMember As TStaffJobReq Set objNewMember = New TStaffJobReq 'set the properties passed into the method objNewMember.NI_Number = NI_Number objNewMember.Expiry = Expiry objNewMember.IsPref = IsPref objNewMember.Status = Status mCol.Add objNewMember, "K" & NI_Number 'return the object created Set Add = objNewMember Set objNewMember = Nothing End Function Public Property Get Item(vntIndexKey As Variant) As TStaffJobReq 'used when referencing an element in the collection 'vntIndexKey contains either the Index or Key to the collection, 'this is why it is declared as a Variant 'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5) On Error GoTo NotFound Set Item = mCol(vntIndexKey) Exit Function NotFound: Set Item = Nothing End Property Public Property Get Count() As Long 'used when retrieving the number of elements in the 'collection. Syntax: Debug.Print x.Count Count = mCol.Count End Property Public Sub Remove(vntIndexKey As Variant) 'used when removing an element from the collection 'vntIndexKey contains either the Index or Key, which is why 'it is declared as a Variant 'Syntax: x.Remove(xyz) mCol.Remove vntIndexKey End Sub Private Sub Class_Initialize() 'creates the collection when this class is created Set mCol = New Collection End Sub Private Sub Class_Terminate() 'destroys collection when this class is terminated Set mCol = Nothing End Sub Public Function StaffJobReqs() As Collection Set StaffJobReqs = mCol End Function 'Class: TStaffJobReq 'local variable(s) to hold property value(s) Private mvarNI_Number As String 'local copy Private mvarExpiry As Date 'local copy Private mvarIsPref As Boolean 'local copy Private mvarStatus As String 'local copy Public Property Let Status(ByVal vData As String) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.IsPreference = 5 mvarStatus = vData End Property Public Property Get Status() As String 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.IsPreference Status = mvarStatus End Property Public Property Let IsPref(ByVal vData As Boolean) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.IsPreference = 5 mvarIsPref = vData End Property Public Property Get IsPref() As Boolean 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.IsPreference IsPreference = mvarIsPref End Property Public Property Let Expiry(ByVal vData As Date) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.ExpiryDate = 5 mvarExpiry = vData End Property Public Property Get Expiry() As Date 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.ExpiryDate ExpiryDate = mvarExpiry End Property Public Property Let NI_Number(ByVal vData As String) 'used when assigning a value to the property, on the left side of an assignment. 'Syntax: X.NI_Number = 5 mvarNI_Number = vData End Property Public Property Get NI_Number() As String 'used when retrieving value of a property, on the right side of an assignment. 'Syntax: Debug.Print X.NI_Number NI_Number = mvarNI_Number End Property


Thats it really I haven't done anything too complex.

Last edited by Flyguy; 02-07-2003 at 01:38 AM.
Reply With Quote
  #4  
Old 01-13-2003, 06:16 AM
Machaira's Avatar
Machaira Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

I had no problems using your classes. See the attached proj. Perhaps if you attached the project instead of just posting the code for the classes?
Attached Files
File Type: zip test.zip (2.6 KB, 5 views)
Reply With Quote
  #5  
Old 01-13-2003, 08:19 AM
Dan Foord
Guest
 
Posts: n/a
Default

Well I got so hacked off with it I deleted the 2 offending elements from the class/modules and then added them back in, in exactly the same way using the class builder utility and hey presto, they work!

Lucky I haven't wasted all of today on it or anything then.... oh and my colleagues who spent a good couple of hours on it hmm.

Thanks for your help. But it was the good old clear out and start again method that worked.

Would have been nice to know why it was knackered though...


Cheers

Dan.
Reply With Quote
  #6  
Old 01-13-2003, 10:35 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

Did you happen to notice what you had in your Property Get?
ExpiryDate = mvarExpiry
That should have been...
Expiry = mvarExpiry
I expect when you cleared out and readded it, it has that line
right now.
__________________
Posting Guidelines
Reply With Quote
  #7  
Old 01-13-2003, 10:42 AM
Dan Foord
Guest
 
Posts: n/a
Default

UGH
Ok I feel pretty 'kin stupid now....
classic.

I can't tell you how many times I stepped through the code.

Thanks and apologies.

Dan

Only saved from Hari Kari by the fact that 2 others at work didn't notice it either!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->