CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Control arrays

  1. #1
    Join Date
    Apr 1999
    Posts
    30

    Control arrays



    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

  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Control arrays



    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




  3. #3
    Join Date
    Apr 1999
    Posts
    30

    Re: Control arrays



    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.

  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Control arrays



    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




  5. #5
    Join Date
    May 1999
    Posts
    45

    Re: Control arrays



    Better if you try vbControlExtender instead of control as it can give you events also, if you need in future.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured