Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How create a property as Array in a User Control (Visual Basic) 1

Status
Not open for further replies.

nbjrbr

Programmer
Feb 28, 2007
5
US

Hi,

I'm trying to develop an ActiveX control (As a Grid) and I need to access the properties of Columns in Run-time mode. Inside of the control, I have an array of a user-defined type.


Type XYZ
Name As String
Order As Integer
End Type

Dim StoreVar(10) As XYZ 'Data from 10 Columns

Property Get Col(ByVal Index As Integer) As XYZ
...
End Property

What I need is to access the name of each column like this:

MyGrid1.Col(1).Name = "XYZ"
MsgBox(MyGrid1.Col(1).Name)

Thanks

Nilson
 
What type of activeX grid, if any, are you using, and how is the data being added to the grid (a loop, or setting a RecordSource/DataSource)?
 
Use class instead UDT, see answer to my similar topic: thread222-720091

combo
 
I guess I read that too fast and completely answered wrong.

I would use a Column Collection Class and a Column class.


But you could also do it as mentioned.
 
Thanks for the help until now, but I still have a problem using the class.
I've created a class module like this

Private v_Name As String
Private V_Order As Integer

Public Property Get Name() As Integer
Name = v_Name
End Property
Public Property Let Name(New_Value As Integer)
v_Name = New_Value
End Property

Then in the UserControl source I did
Dim StoreData() As MyClass
Redim StoreData(2)
Set StoreData(0) = new MyClass
Set StoreData(1) = new MyClass

Public Property Get Col(ByRef Index As Integer) As MyClass
Col = StoreData(Index)
End Property

but doesnt work. when I insert an object in the form and try to access the data like:

MsgBox(Obj.Col(0).Name)

I received a runtime 91 - Object variable or with object variable not set in the line of the Get Col property.

Nilson
 
You have two problems:

1. Must be the same type
Private v_Name As String
Private V_Order As Integer

Public Property Get Name() As Integer
Name = v_Name
End Property
Public Property Let Name(New_Value As Integer)
v_Name = New_Value
End Property


2. Need to use Set
Set Col = StoreData(Index)


Also to note:
You have redimmed your StoreData array with 3 elements (0,1,2) but are only using 2 of them. This is also an area where an error may happen.
 

Ok, the difference between types was a transcription problem :). Thanks a lot for the answer, now its working !!!

Regards

Nilson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top