| Mirage Source http://web.miragesource.net/forums/ |
|
| Array in a Class http://web.miragesource.net/forums/viewtopic.php?f=201&t=5141 |
Page 1 of 1 |
| Author: | Robin [ Sun Mar 01, 2009 3:47 pm ] |
| Post subject: | Array in a Class |
I need to store a byte array within my 'clsAccount' class file. I have it like this: Code: Private account_Buffer() As Byte But I keep pulling up an error whenever I try and call Player(index).Buffer Here's my get/let: Code: Public Property Get Buffer() As Byte Buffer = account_Buffer() End Property Public Property Let Buffer(ByVal vData As Byte) account_Buffer() = vData End Property I also tried: Code: Public Property Get Buffer(ByVal iI As Long) As Byte If iI >= 0 And iI <= UBound(account_Buffer) Then Buffer = account_Buffer(iI) End If End Property Public Property Let Buffer(ByVal iI As Long, ByVal vData As Byte) If iI >= 0 And iI <= UBound(account_Buffer) Then account_Buffer(iI) = vData End If End Property But I need the entire array for my code, not just a single part of it. Read around and saw a couple of pieces talking about Collections, but I'm still at a loss on how I can grab the entire array in one call. |
|
| Author: | Dragoons Master [ Sun Mar 01, 2009 6:01 pm ] |
| Post subject: | Re: Array in a Class |
I maneged to make a working version, but I don't know exactly how to get the value with direct access to the variable. Well, try for your self: Code: Option Explicit Private account_Buffer() As Byte Private Sub Class_Initialize() ReDim account_Buffer(1 To 10) As Byte Dim i As Long For i = 1 To 10 account_Buffer(i) = i Next i End Sub Public Property Get Buffer() As Byte() Buffer = account_Buffer End Property Public Property Get Item(ByVal index As Integer) As Byte Buffer = account_Buffer(index) End Property Public Property Let Item(ByVal index As Integer, ByVal value As Byte) account_Buffer(index) = value End Property Public Property Let Buffer(ByRef vData() As Byte) account_Buffer = vData End Property And the Form1 example: Code: Private Sub Form_Load() Dim vari As Class1 Set vari = New Class1 Dim haha() As Byte vari.Item(1) = 2 haha = vari.Buffer Dim i As Long For i = 1 To 10 MsgBox haha(i) Next i End Sub EDIT: Now it works, but since you can't overload in vb6, you cant use the same name for both functions. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|