Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » General

Post new topic   Reply to topic
Creating Labels with Code
View previous topic :: View next topic  
Author Message
mt_reilly
Newbie


Joined: 13 Nov 2003
Posts: 3

PostPosted: Nov 13th, 2003 02:32 PM    Post subject: Creating Labels with Code Reply with quote

I am trying to create Labels with Code, rather than using the tool bar and drawing them with a mouse. I've tried the code below, but this resulted in a run-time error 91. Any suggestions on how to do this?

Private Sub Form_Load()

Dim lbl() As label
ReDim lbl(3)
For i = 1 To 3
With lbl(i)
.Height = 30
.Width = 30
.Caption = i
.Left = 300 * i
End With
Next i

End Sub
Back to top
View user's profile Send private message Send e-mail
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Nov 14th, 2003 01:20 AM    Post subject: Reply with quote

Hi!

Here you go with the code...its a bit modified and creates only 3 controls for now but i think you can modify according to your needs.

Code:
Dim Ctl As Control

For I = 1 To 3
    Set Ctl = Form1.Controls.Add("VB.Label", "Label" & I, Form1)
   
    Ctl.Caption = I - 1
    Ctl.Visible = True
    Ctl.Top = 550 * I
    Ctl.Left = 150
    Ctl.Width = 2500
    Ctl.Height = 550
Next


Hope this helps!
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Nov 14th, 2003 04:19 PM    Post subject: Reply with quote

You can't make a control array the way Avis pointed out. The index property isn't set and you can't set it at runtime. If you want a control array you have to set it at design time.
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic