WhiteRabbit
New Member
- Joined
- Apr 15, 2013
- Messages
- 4
I have a Data sheet filled with resources. Each resource has a name, location, and title. I made a class called Resource [see below]. I'm trying to iterate through the Data sheet and store all the resource information into objects, which are then stored in an array.
So there's a Name column, Title, and Location. I get the number of rows in the document, and for each row i look for the name, the title, and location of the resource, make a new object, and store it in the array. Then I go to the next row, until there's no more data.
Here's what I have so far. I'd really appreciate any advice. Obviously this code isn't functional yet.
Here's the class:
Here's what I have so far of the Sub.
So there's a Name column, Title, and Location. I get the number of rows in the document, and for each row i look for the name, the title, and location of the resource, make a new object, and store it in the array. Then I go to the next row, until there's no more data.
Here's what I have so far. I'd really appreciate any advice. Obviously this code isn't functional yet.
Here's the class:
Code:
Private pName As String
Private pCity As String
Private pTitle As String
''''''''''''''''''''''
' Name property
''''''''''''''''''''''
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Name(Value As String)
pName = Value
End Property
''''''''''''''''''''''
' City property
''''''''''''''''''''''
Public Property Get City() As String
City = pCity
End Property
Public Property Let City(Value As String)
pCity = Value
End Property
''''''''''''''''''''''
' Title property
''''''''''''''''''''''
Public Property Get Title() As String
Title = pTitle
End Property
Public Property Let Title(Value As String)
pTitle = Value
End Property
Here's what I have so far of the Sub.
Code:
Sub ArrayPractice()
Dim r As Integer
Dim i As Integer
Dim a As Integer
Dim numberOfRows As Integer
Dim names() As String
r = 2 'row that i start looping from
a = 0
numberOfRows = ActiveSheet.UsedRange.Rows.Count
Dim resourceArray(numberOfRows) As Resource
For i As Integer = 0 to numberOfRows 'Getting an error here.
resourceArray(i) = New Resource
' Make the new Resource object here??
Next i
ReDim names(0) 'redimension the array to size zero
Do Until Cells(r, 1).Value = ""
names(i) = Cells(r, 1).Value
i = i + 1 'increment index of the array
ReDim Preserve names(i) 'size is equal to the next index.
r = r + 1
Loop
''''print the array!''''
For i = 0 To UBound(names) - 1 'ubound is equal to one number higher
Cells(r, 2).Value = names(i)
r = r + 1
Next i
End Sub