|
-
Jul 10th, 2013, 12:31 AM
#1
Thread Starter
New Member
VB6 - Get accessor not working for array property
I have two properties in my VB6 code:
Code:
Public Property Get PropFileID() As Long
PropFileID = m_FileID
End Property
Code:
Public Property Get PropFileIDArray() As Long()
PropFileIDArray = m_FileIDArray
End Property
While debugging, I can see the first property (PropFileID) being assigned a value without error. m_FileID has a value, and after passing through the Get accessor, PropFileID gets the same value.
While debugging the second property (PropFileIDArray), I can see that m_FileIDArray has a valid array value. However, after passing through the Get accessor, PropFileIDArray remains empty.
Am I making some kind of error in the syntax?
Any suggestions would be greatly appreciated
-
Jul 10th, 2013, 02:47 AM
#2
Re: VB6 - Get accessor not working for array property
I hope the following will shed some light on this:
Code:
Option Explicit
Private m_FileIDArray() As Long
Private Sub Form_Initialize()
ReDim m_FileIDArray(0 To 2)
m_FileIDArray(1) = 1
m_FileIDArray(2) = 2
End Sub
Public Property Get PropFileIDArray() As Long()
PropFileIDArray = m_FileIDArray
End Property
Private Sub Form_Load()
'this works in principle (on temporary "live-copies" of the Long-Array)
Debug.Print "Bounds:"; LBound(PropFileIDArray); "To"; UBound(PropFileIDArray)
'access by index will not work directly, because the Property-Get
'is seen as a Function - and this Function currently has no Params defined in its signature:
'Debug.Print PropFileIDArray(1)
'this here will work, since we treat the Function-result
'in its shortlived, temporary state as a "separate entity"
Debug.Print PropFileIDArray()(1)
'to avoid all those shortlived temp-copies, just treat the Prop
'as the Function it really is - and store the copy of the
'internal array in a "receiver-variable":
Dim LArr() As Long
LArr = PropFileIDArray
Debug.Print LArr(0), LArr(1), LArr(2)
End Sub
Olaf
-
Jul 10th, 2013, 05:26 AM
#3
Re: VB6 - Get accessor not working for array property
Example:
Class1
Code:
Option Explicit
Private mArr() As Long
Public Property Get A() As Long()
A = mArr
End Property
Private Sub Class_Initialize()
ReDim mArr(1)
mArr(0) = 7654321
mArr(1) = 8888888
End Sub
Form1
Code:
Option Explicit
Private Sub Command1_Click()
Dim B() As Long
With New Class1
B = .A
MsgBox B(0)
MsgBox .A()(1)
End With
End Sub
Works fine here.
My guess is that you have some other problem such as your m_FileIDArray being uninitialized. For all we know you have a typo in the name and failed to use Option Explicit.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|