473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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_Manager.Frame1.Label !!!!!!
With ctlNew
.Name = "Label" & x & Trim(CStr(i))
.Text = .Name
.Visible = True
.Width = 1335
.Top = 720
.Left = 120
End With
UF_Inventory_Manager.Controls.Add (ctlNew)
next


Any help is greatly appreciated.
Oct 26 '06 #1
5 8749
Killer42
8,435 Expert 8TB
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
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Click()
    2.   Dim I As Long
    3.   For I = 1 To 5
    4.     Load Label1(I)
    5.     With Label1(I)
    6.       .Move I * 180, I * 180
    7.       .Caption = "Label #" & I
    8.       .Visible = True
    9.     End With
    10.   Next
    11. End Sub
  • Run your project, and click on the form (outside the frame)
Oct 27 '06 #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
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Click()
    2.   Dim I As Long
    3.   For I = 1 To 5
    4.     Load Label1(I)
    5.     With Label1(I)
    6.       .Move I * 180, I * 180
    7.       .Caption = "Label #" & I
    8.       .Visible = True
    9.     End With
    10.   Next
    11. 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.
Oct 31 '06 #3
Killer42
8,435 Expert 8TB
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.
Oct 31 '06 #4
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),Label2(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!
Oct 31 '06 #5
Killer42
8,435 Expert 8TB
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),Label2(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.
Oct 31 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: duncan.lovett | last post by:
I am working on a graphical heading generator for a clients website as their server does not have the GD library or similar plugins for dynamic image generation. I have achieved the result...
11
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to...
9
by: wASP | last post by:
Hello again to all of you geniuses, I'm having a problem trying to load dynamic controls at the initialization phase. I've read the docs, and I thought I had it figured out:...
7
by: Venus | last post by:
Hello, I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows Build up the string that is placed somewhere in the HTML code the...
4
by: Venus | last post by:
Hello, Thanks for your reply. I understand that a control can be created dynamically in several ways: 1) using StringBuilder 2) using Controls.Add 3) using ASP PlaceHolder But this is just...
0
by: Venus | last post by:
Hello, After trying some ways to do it I wanted to use something like the code below but for some reason is not working (I have to generate the entire form dynamically (not only the controls)):...
2
by: Ghada Al-Mashaqbeh via DotNetMonster.com | last post by:
Hi all, I am facing a problem in dynamic code generation at run time, the problem occurs when the dynmaic code use global data exist within the original application. Lets say that my...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.