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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a dynamic array 3

Status
Not open for further replies.

Trowser

IS-IT--Management
Dec 16, 2002
125
GB
ok I have been lookiing in the quick tips and it shows in there how to make a dynamic controls to get around the limit of controls in a form.
Now how do you create an array I may need to make upto 50 dynamic labels but I dont want to go

Dim Label1 as VB.Label

For each one, I want to create an array and then set the parameters for the whole array.

Can someone show me on how to create an array of labels dynamically?
 
What I would do is create the first label on the form, and assign it an Index Value of 0.

Inside the program, in the declarations section, create a public variable called Label Count, then initialize it to 0 in the Form_Load.

When you want to add another label to the form, then
Code:
LabelCount = LabelCount + 1
Load lblLabel(LabelCount)
then position it
Code:
lblLabel(LabelCount).Top = 123
and so forth.

Then be sure to unload all of them in the form unload.
Code:
For Idx = 1 to LabelCount  ' start at 1
   Unload lblLabel(LabelCount)
Next Idx
LabelCount = 0
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Perfect m8 as they say in britan

Its the dogs bollocks :)

Thanks alot
 
hmm small problem

LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 226
LblImgMap(LabelCount).Top = 244
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 224
LblImgMap(LabelCount).Top = 476
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 344
LblImgMap(LabelCount).Top = 448
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 442
LblImgMap(LabelCount).Top = 386
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 502
LblImgMap(LabelCount).Top = 298
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 532
LblImgMap(LabelCount).Top = 124
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 652
LblImgMap(LabelCount).Top = 80
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 818
LblImgMap(LabelCount).Top = 210

ok added in this code but the labels seem non existant but it doesn't error out. Now I created the label gave it all the properties I wanted like the mouseicon etc moved it off the form so that it couldn't be seen but when I run the above code like suggested no labels appear.
Am I doing something wrong?
 
When you use Load you need to explicitly make the object visible:

LblImgMap(LabelCount).Visible = True
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
First think I would do is to create an Add Label Routine, and code to set the visible property, and whatever other properties you need to set. Then the code that you have above would look as follows:

AddLabel 226, 244
AddLabel 224, 476
AddLabel 344, 448
AddLabel 442, 386
AddLabel 502, 298
AddLabel 532, 124
AddLabel 652, 80
AddLabel 818, 210

Sub AddLabel (SetLeft as Integer, SetTop as Integer)

LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = SetLeft
LblImgMap(LabelCount).Top = SetTop

LblImgMap(LabelCount).Visible = True

End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
In the previous post, I left out the Load
Load lblLabel(lblLabel.Ubound + 1)

For the other problem, I do not remember if Load copies the Container property but in case your labels are on a frame then add

Set lblLabel(lblLabel.Ubound).Container = lblLabel(0).Container Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Option Explicit
Public LabelCount As Integer

Private Sub Form_Load()
LabelCount = 0
End sub

Private sub mnuAlpha_Click()
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 226
LblImgMap(LabelCount).Top = 244
LblImgMap(LabelCount).Visible = True
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 224
LblImgMap(LabelCount).Top = 476
LblImgMap(LabelCount).Visible = True
LblImgMap(LabelCount).Enabled = True
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 344
LblImgMap(LabelCount).Top = 448
LblImgMap(LabelCount).Visible = True
LblImgMap(LabelCount).BackColor = &HFF&
End Sub

ok tried all this in order to try to see the labels and I get zip and no errors.

form loads
user interacts
depending on user selection labels load up on the form

I get all the way through but get no labels still

 
As soon as I see labels I think I will do what cajun suggested with the label routine
 
What are the properties that you establed for the LblImgMap(0), added to the form thru the IDE? Make sure that you set the border property, and you may also want to assign a caption to the labels. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Can you stick this in the code:

You have:
LabelCount = LabelCount + 1
Load LblImgMap(LabelCount)
LblImgMap(LabelCount).Left = 226
LblImgMap(LabelCount).Top = 244
LblImgMap(LabelCount).Visible = True
Add this:
MsgBox LblImgMap(LabelCount).Left

If the msgbox comes up then you've got the label, but can't see it for some reason. If it doesn't come up then the code isn't running for some reason. If an error comes up then the code is running but the Lbl has not been generated for some reason

Let us know what happens
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
ok john it returned the value of the Labels distance form the left side of the form in the msgbox

so its there :) great :)

just cannot see it

Also all the properties for the original lavel as follows

Name = LblImgMap
Autosize = False
Backstype = opaque
Borderstyle = none
Caption = ""
Size = 15pixels x 15pixels
Mousepointer = Arrow and question (14)

everything else is default

 
I know this seems obvious but it's not behind another control is it?

To make sure its on top use:

LblImgMap(LabelCount).ZOrder

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
When you add the label, give it a caption value, and give the label a height as well.

You might also make all of the other controls invisible until we find the labels. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Bingo John
Because the original control was at the front I assumed the other controls would also sit on the front but it seems that in this case they decided to hide.

Also it has now shown me that the positions they are in seems to be in twips rather than in pixels so that gives me something else to change

Thank you all for your help maybe one of you big bod's should write a tip on this as creating dynamic controls seems to be covered but this array thing seems to be quite a bit differant :) would hate for anyone else to have to go through this aswell :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top