•
•
•
•
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,523 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,858 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: 529 | Replies: 4 | Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 40
Reputation:
Rep Power: 1
Solved Threads: 0
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:
(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.
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
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.
•
•
Join Date: Feb 2008
Location: Sivakasi, Tamilnadu, India
Posts: 458
Reputation:
Rep Power: 1
Solved Threads: 79
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
This is normal, But u can have global variable instead
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
but you need to Mention the function name while accessing it thru object
For Ex
I hope this is helpful somewhat to you.
For Ex
'in a Class
VB Syntax (Toggle Plain Text)
Private mLength As Integer Public Property Get Length() As Integer Length = mLength End Property Public Property Let Length(ByVal vNewValue As Integer) mLength = vNewValue End Property
VB Syntax (Toggle Plain Text)
Public Length as Intger
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
VB Syntax (Toggle Plain Text)
Private mLength As Integer Public Function GetLength() As Integer GetLength = mLength End Sub Public Sub SetLength(ByVal vNewValue As Integer) mLength = vNewValue End Sub
For Ex
VB Syntax (Toggle Plain Text)
Dim C as New Class1 Dim Length as Integer C.SetLength 100 'Instead of C.Length = 100 Length = C.GetLength() 'Instead of Length = C.Length
Last edited by selvaganapathy : Jul 24th, 2008 at 10:22 pm.
KSG
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....
Code for GetLength remains the same..
Regards
Veena
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....
vb Syntax (Toggle Plain Text)
Public Sub SetLength(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 Sub
Code for GetLength remains the same..
Regards
Veena
•
•
Join Date: Jan 2008
Posts: 40
Reputation:
Rep Power: 1
Solved Threads: 0
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Apache (Linux Servers and Apache)
- This is a wierd one! (Windows NT / 2000 / XP / 2003)
- God-awful lags in Internet Explorer (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how to use MSFlexGrid in VB ?
- Next Thread: Difficulty in reading data thru Com port


Linear Mode