Log in

View Full Version : VBA - type deficition/declaration & use



kato01
05-17-2011, 08:17 AM
Hello,

I am trying to define an array of structures (points) with three properties: name, z_value, rho_value
this is in a module in excel.
It does not work
Please advise

Thank you
Katto01

---------------------------------
Type points
name As String
z_value As Double
rho_value As Double

End Type

Public pp() As points

Public Sub make_Omni_Polyrod()
Dim p() As pp
np = 16
ReDim p(16)

For i = 1 To np
p.name(i) = Cells(i + 1, 2).Text
p.z(i) = Cells(i + 1, 3).Value
p.rho_value(i) = Cells(i + 1, 4).Value
Next i
End Sub
---------------------------------

Tommy
05-17-2011, 10:24 AM
This should straighten it out

Type points
name As String
z_value As Double
rho_value As Double
End Type
Public pp() As points
Public Sub make_Omni_Polyrod()
Dim p() As pp
np = 16
ReDim p(16)

For I = 1 To np
p(I).name = Cells(I + 1, 2).Text
p(I).z = Cells(I + 1, 3).Value
p(I).rho_value = Cells(I + 1, 4).Value
Next I
End Sub

kato01
05-18-2011, 05:26 AM
thanks, that was easy