User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 426,810 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,924 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 530 | Replies: 4 | Solved
Reply
Join Date: Jan 2008
Posts: 40
Reputation: Tekito is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Tekito Tekito is offline Offline
Light Poster

Issue with Get and Let properties in Class Module

  #1  
Jul 24th, 2008
I'm new to class modules, and the compiler seems to be enforcing a correlation of the number of input vars for a Get and Let procedure of the same property. The Let property must always have exactly one more variable (the NewValue) than the Get procedure. So the code I've got below does not work, because of the discrepancy in input vars:

Property Get Length() As Integer

  Length = UBound(mProj, 2)

End Property

Property Let Length(NewVal As Integer, Clear As Boolean)

If NewVal < 0 Then Err.Raise 50000, , "Value cannot be negative."
If Clear = True Then
    ReDim mProj(1, NewVal)
Else
  ReDim Preserve mProj(1, NewVal)
End If

End Function
(i altered a bit for clarity so there might be a minor mistake)

My question is why does this have to be the case? It seems that a person, when setting a property to a certain value, might have an untold number of factors affecting the decision, which should be passed as variables. But to simply retrieve this certain property might require no input variables at all.
It just seems like such a strange issue to a fundamental situation, so I was wondering if anyone knows of a workaround, or if I'm missing something, etc.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Argentina
Posts: 51
Reputation: dmf1978 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 7
dmf1978's Avatar
dmf1978 dmf1978 is offline Offline
Junior Poster in Training

Re: Issue with Get and Let properties in Class Module

  #2  
Jul 24th, 2008
Hi,
Think of a property just as if it were a regular variable. You can get or assign only one value at once.
If you need to pass more than one parameter to a property, instead use a regular Sub procedure.

Hope it helps,
-- Martín
Reply With Quote  
Join Date: Feb 2008
Location: Sivakasi, Tamilnadu, India
Posts: 458
Reputation: selvaganapathy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 79
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro in Training

Re: Issue with Get and Let properties in Class Module

  #3  
Jul 24th, 2008
Yes, I agree dmf1978 points, Property is a special feature in VB6. It encapsulates a private member variable inside a class.

For Ex
'in a Class
  1. Private mLength As Integer
  2. Public Property Get Length() As Integer
  3. Length = mLength
  4. End Property
  5.  
  6. Public Property Let Length(ByVal vNewValue As Integer)
  7. mLength = vNewValue
  8. End Property
This is normal, But u can have global variable instead
  1. Public Length as Intger
Here the Problem is "you cannot restrict the Value when it is Public variable" but you can do it in Properties.

Get and Let/Set Properties represents the Same thing. SO the Compiler enforce you to the Correct Syntax.

If you want give so many Option You can go For Procedure or Function.
This is available in Other Languages to Access the private Member GetXXX() and SetXXX() Functions.
So the AboveCode Can be
  1. Private mLength As Integer
  2. Public Function GetLength() As Integer
  3. GetLength = mLength
  4. End Sub
  5. Public Sub SetLength(ByVal vNewValue As Integer)
  6. mLength = vNewValue
  7. End Sub
but you need to Mention the function name while accessing it thru object
For Ex
  1. Dim C as New Class1
  2. Dim Length as Integer
  3.  
  4. C.SetLength 100 'Instead of C.Length = 100
  5. Length = C.GetLength() 'Instead of Length = C.Length
I hope this is helpful somewhat to you.
Last edited by selvaganapathy : Jul 24th, 2008 at 10:22 pm.
KSG
Reply With Quote  
Join Date: Nov 2006
Posts: 712
Reputation: QVeen72 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 97
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Master Poster

Re: Issue with Get and Let properties in Class Module

  #4  
Jul 25th, 2008
Hi,

Yes, I concur with both of the above...
for Property , you can Get or Let only one Value parameter.
Since, you are wanting to pass 2 parameters, Create SetLength, as a Public Sub Procedure and not a Property....

  1. Public Sub SetLength(NewVal As Integer, Clear As Boolean)
  2. If NewVal < 0 Then Err.Raise 50000, , "Value cannot be negative."
  3. If Clear = True Then
  4. ReDim mProj(1, NewVal)
  5. Else
  6. ReDim Preserve mProj(1, NewVal)
  7. End If
  8. End Sub

Code for GetLength remains the same..


Regards
Veena
Reply With Quote  
Join Date: Jan 2008
Posts: 40
Reputation: Tekito is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Tekito Tekito is offline Offline
Light Poster

Re: Issue with Get and Let properties in Class Module

  #5  
Jul 25th, 2008
Thanks for the responses. I guess I understand that the Get and Let procedures serve specific purposes, and aren't supposed to be substitutes for procedures in general. I had already started making a SetLength procedure before these responses, but now seeing that is what you guys would also do, I know I'm on the right track. Thanks.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 7:55 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC