Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects
Referencing Dynamically Created Objects Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Go Back  Xtreme Visual Basic Talk > > > > Referencing Dynamically Created Objects


Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2017, 09:35 PM
EElearningVB EElearningVB is offline
Freshman
 
Join Date: Oct 2010
Posts: 29
Default Referencing Dynamically Created Objects


Hi Everyone,

Trying to reference a dynamically created object which can either be set as an array of objects or a collection (I am new to collections).

Create Objects
-----------------------------------------
Code:
Public labelCounter As Integer

Sub BuildForm()
    Dim intDayOfWeek As Integer
    Dim lblMapping As Object
    Dim theButton As Object
    Dim theButton2 As Object
    Dim txtWeight As Object
    
    
    labelCounter = 1
    intDayOfWeek = Weekday(Date)
    
    Sheets(CStr(intDayOfWeek)).Select
    Range("A1").Select
    
    Do Until ActiveCell.Value = "Mapping"
        ActiveCell.Offset(0, 1).Select
    Loop
    
    ActiveCell.Offset(1, 0).Select
        
    Do Until ActiveCell.Value = ""
            Set lblMapping = UserForm2.Controls.Add("Forms.Label.1", "lblMapping" & labelCounter, True)
            With lblMapping
                .Name = "lblMapping" & labelCounter
                .Caption = ActiveCell.Value
                .Left = 10
                .Width = 100
                .Top = 17 * labelCounter
            End With

            Set txtWeight = UserForm2.Controls.Add("Forms.TextBox.1", "txtWeight" & labelCounter, True)
            With txtWeight
                .Name = "txtWeight" & labelCounter
                .Text = "Weight"
                .Left = 120
                .Width = 50
                .Top = 17 * labelCounter
                .Text = txtWeight.Name
            End With
            
            labelCounter = labelCounter + 1
            ActiveCell.Offset(1, 0).Select
    Loop

    With UserForm2.cmdCancel
        .Caption = "Cancel"
        .Top = labelCounter * 17 + 50
        .Left = 20
    End With

    With UserForm2.cmdSubmit
        .Caption = "Submit"
        .Top = labelCounter * 17 + 50
        .Left = UserForm2.cmdCancel.Left + UserForm2.cmdCancel.Width + 15
    End With
    
    UserForm2.Show

End Sub
Trying to reference value of textbox. I cannot determine how to pull the name to get the value.
Code:
Private Sub cmdSubmit_Click()
Dim intWeight() As Integer
Dim x As Integer

ReDim intWeight(0 To labelCounter)

For x = 1 To labelCounter
    intWeight() = UserForm2.txtWeight(x).Value '------Need name of textbox or way to access values. Tried both arrays and collections though I couldn't get that to work either

    lblTest.Caption = lblTest.Caption & " " & CStr(intWeight(x))
Next x
Thank You!!

Last edited by Flyguy; 03-09-2017 at 01:55 AM.
Reply With Quote
  #2  
Old 03-09-2017, 08:27 AM
MPiReferencing Dynamically Created Objects MPi is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Dec 2001
Location: Quebec
Posts: 1,000
Default

You may try this
Code:
intWeight(x) = UserForm2.Controls("txtWeight" & x).Value
__________________
MPi²
Reply With Quote
Reply

Tags
labelcounter, dim, txtweight, lblmapping, object, integer, .left, .top, activecell.value, .caption, set, objects, reference, .width, dynamically, activecell.offset1, .name, 0.select, true, intweight, created, textbox, .text, loop, collections


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
 
Referencing Dynamically Created Objects
Referencing Dynamically Created Objects
 
-->