dynamic label array generation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackwellam
    New Member
    • Oct 2006
    • 3

    #1

    dynamic label array generation

    Hi,

    Firstly apologies for asking a similar question to one I know has been covered before but I'm quite new to visual basic and dont really understand the answers or how to get the next step. Im looking to dynamically generate a label array with three label 'boxes' per array.

    Labelx(0)
    Labelx(1)
    Labelx(2)

    The number of arrays 'x' is given by an integer value. To complicate matters slightly tho the labels are to be created within a frame on a userform. So far I have a basic attempt (very similar to another thread here!) to get even one appearing but its missing an object definition I think (tho I cant seem to find out which I need!).

    x=2
    For i = 1 To x
    'Dim ctlNew As New UF_Inventory_Ma nager.Frame1.La bel !!!!!!
    With ctlNew
    .Name = "Label" & x & Trim(CStr(i))
    .Text = .Name
    .Visible = True
    .Width = 1335
    .Top = 720
    .Left = 120
    End With
    UF_Inventory_Ma nager.Controls. Add (ctlNew)
    next


    Any help is greatly appreciated.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Hi. You could try this:
    • Create a new form
    • On your form, create a frame (default name Frame1, I guess).
    • In the frame, create a label (default name Label1, I guess).
    • Set the Index property of the label to 0.
    • Set the Visible property of the label to False.
    • Add this code to the form
      Code:
      Private Sub Form_Click()
        Dim I As Long
        For I = 1 To 5
          Load Label1(I)
          With Label1(I)
            .Move I * 180, I * 180
            .Caption = "Label #" & I
            .Visible = True
          End With
        Next
      End Sub
    • Run your project, and click on the form (outside the frame)

    Comment

    • blackwellam
      New Member
      • Oct 2006
      • 3

      #3
      Originally posted by Killer42
      Hi. You could try this:
      • Create a new form
      • On your form, create a frame (default name Frame1, I guess).
      • In the frame, create a label (default name Label1, I guess).
      • Set the Index property of the label to 0.
      • Set the Visible property of the label to False.
      • Add this code to the form
        Code:
        Private Sub Form_Click()
          Dim I As Long
          For I = 1 To 5
            Load Label1(I)
            With Label1(I)
              .Move I * 180, I * 180
              .Caption = "Label #" & I
              .Visible = True
            End With
          Next
        End Sub
      • Run your project, and click on the form (outside the frame)

      Hi thanks for the reply, still no joy tho I'm afraid says it doesnt like Load Label (Am I missing a blatently obvious reference definition?). Im trying to go down the lines of your suggestion by copying existing hidden labels then pasting and repositioning them into the UF. Kinda crude but if it works at the moment I dont mind. Only snag is I cant seem to find out how to do this copy/paste action if its even possible!? Any ideas would be greatly appreciated.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Keep these points in mind:
        • Check the spelling of the control's name - you might have got it wrong in the code.
        • To be able to use load, I believe the label must be a control array.
        • To make it an array, it must have a value in the Index property. Blank is not the same as zero.
        If all else fails, try starting with a fresh project and going through step by step from scratch. Once it works (confident, aren't I :)) then you can play around with it.

        Comment

        • blackwellam
          New Member
          • Oct 2006
          • 3

          #5
          Yes, yes you are! For good reason too me thinks. Just did exactly what you said with it in a plain UF and worked a treat only thing is it only moves Label1(1) correctly and the rest go off the screen but I reckon that can be sorted with either a mod to the .move or by specifying a .top and .left. Hmmmm now all I have to do is massage that into my code.

          As I have a series of Labels Label1(0),Label 2(0) do you know of a way I can define these as at the moment I've got 'Load Label & x & (i)' where x is an integer and i the index value but it doesnt like that.

          Thanks for all your help!

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by blackwellam
            Yes, yes you are! For good reason too me thinks. Just did exactly what you said with it in a plain UF and worked a treat only thing is it only moves Label1(1) correctly and the rest go off the screen but I reckon that can be sorted with either a mod to the .move or by specifying a .top and .left. Hmmmm now all I have to do is massage that into my code.

            As I have a series of Labels Label1(0),Label 2(0) do you know of a way I can define these as at the moment I've got 'Load Label & x & (i)' where x is an integer and i the index value but it doesnt like that.

            Thanks for all your help!
            Hm... don't think I can help with the "& x &" business, as I'm not sure I understand what you mean.

            As for the label going off the screen, as far as I know the .Move method should produce exactly the same results as setting .Top and .Left properties, except that it accomplished in a single action rather than two. It's probably just something to do with your default scale mode, or something. If you're not sure where you want to position something, just shove a control there manually, then check what the Top and Left values are (shown on the "standard" toolbar, if we're talking about VB6). This one should be a simple matter of fiddling around to get the feel for it.

            Comment

            Working...