Solved

Creating objects on a form using Form_Load.....

Posted on 2001-06-20
9
153 Views
Last Modified: 2010-05-02
Ok, this one is a bit harder.

I want 31 new labels for my form, with the values 1 - 31. I know there must be an easier way to add them other then manually enter them in, so I thought I would ask the experts!!

I appreciate any help

Lewis Keen
a.k.a Yeggstry
0
Comment
Question by:yeggstry
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6211913
Dim lbl As Label
Dim cnt As Integer

LastTop = 0
For cnt = 1 to 31
  Set lbl = Me.Controls.Add("VB.Label", "lbl" & cnt)
  With lbl
    .Move 10, cnt
    .AutoSize = True
    .Visible = True
    .Caption = cnt
  End With
Next cnt


try that maybe?
0
 

Author Comment

by:yeggstry
ID: 6211923
cheers, i will try, but any other solutions are welcome!!
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6211933
also you can add one label to your form, name it lblNumbers and set its index property to 0. then:

Dim cnt as Integer

for cnt = 1 to 31
  Load lblNumbers(lblNumbers.UBound + 1)
  With lblNumbers(lblNumbers.UBound)
    .Top = lblNumbers(lblNumbers.UBound - 1).Top + .Height
    .Left = 10
    .Caption = cnt
    .Visible = True
  End With
Next cnt
0
 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
ID: 6212637
To add labels at design time, use some add-in or create your own.
Simple sample:
Start new Add-In project (menu File, New Project, AddIn) - this will create Connect.Dsr and frmAddIn form.
Replace code in frmAddIn with this:

' frmaddIn, add one textbox (2 buttons are already on form)
Option Explicit
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Private Sub CancelButton_Click()
    Connect.Hide
End Sub

Private Sub Form_Load()
    Caption = "Enter number of labels on new form"
    Text1.Text = "31"
End Sub

Private Sub OKButton_Click()
    Dim myC As VBControl, thisF As VBForm, i As Integer
    On Error Resume Next
   
    ' add new form
    Set thisF = VBInstance.VBProjects(1).VBComponents.Add(vbext_ct_VBForm).Designer
    For i = 1 To CInt(Text1.Text)
        Set myC = thisF.ContainedVBControls.Add("VB.Label")
        myC.Properties("Visible") = True
        myC.Properties("left") = 300
        myC.Properties("top") = i * 225
        myC.Properties("name") = "Label" & CStr(i)
        myC.Properties("height") = 225
        myC.Properties("width") = 2775
        myC.ControlObject.Caption = CStr(i)
    Next
End Sub
' -------------------------------------
To test addin, press F5, start new instance of VB, and click menu Add-Ins, My Addin.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6213138
ameba,
thats interesting.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6453660
Why did you punish me with a B ???

If something wasn't clear, you should have asked for clarification or for more info.

Do NOT expect any further help from me!
0
 

Author Comment

by:yeggstry
ID: 6453672
grow up ameba

I gave you a B because your answer was sufficient, but could have been better.
0
 
LVL 15

Expert Comment

by:ameba
ID: 6454272
>grow up ameba

Some people really don't deserve ANY HELP!
0
 

Expert Comment

by:amp072397
ID: 6711598
Well, I've found my way to this question rather indirectly. However, B grades are not given if the answer was sufficient. Yeggstry, I'll gladly post the guidelines for grading. If you did not know the answer, how could you possibly know that the answer could have been better?

Changing grade to an A...

amp
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now