Click to See Complete Forum and Search --> : Control arrays


Rupert Bates
February 19th, 1999, 06:46 AM
I have a problem with control arrays, which I would be interested to see if anyone has an answer for.

If I have a control array of 'UIElement' controls I can access their individual positions as follows:

UIElement(0).Left

UIElement(0).Top

etc.


However I can't do the following:

dim uie as UIElement

set uie = UIElement(0)


and then access the position of that UIElement:

uie.left

uie.top


this will cause an error 'Method or data member not found' because the individual UIElement no longer has these properties. The only way to access these (and other) properties is through the control array.


I have two questions, one is there a workaround for this? And two Don't you think this is a daft way for VB to behave?


Rupert

Chris Eastwood
February 19th, 1999, 07:20 AM
Hi


I'm not sure if I understand your problem, because I cannot reproduce your problem, but ...


>dim uie as UIElement

>set uie = UIElement(0)


This would imply to me that you have a control array called UIElement - therefore you cannot define a variable as UIElement.


I tried this with a control array of labels - Create a form (form1), add a label (label1) - create 4 more labels from label1 (ie. index 0,1,2,3,4)


Dim lbl As Label



Set lbl = Label1(2)



lbl.Left = lbl.Left * 2




This code worked fine.


You can always reference an element in a control array using 'With', eg:


With UIElement(0)

.Left = Whatever

.Right = Whatever

.DoSomeStuff

End With


Regards


Chris Eastwood


CodeGuru - the website for developers

http://www.codeguru.com/vb

Rupert Bates
February 19th, 1999, 08:32 AM
Yes, you're right, this does work ok with intrinsic VB controls. I am trying to do it with UserControls though and for these, it doesn't work.

Chris Eastwood
February 19th, 1999, 08:58 AM
ahhh...


How about :


Dim ctl As Control


Set ctl = UIElement(0)

ctl.Left = xxxxx


Regards


Chris Eastwood


CodeGuru - the website for developers

http://www.codeguru.com/vb

Vinayak Sapre
March 1st, 1999, 12:30 AM
Better if you try vbControlExtender instead of control as it can give you events also, if you need in future.