[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

dynamically adding labels

Posted on 2009-04-16
7
Medium Priority
?
191 Views
Last Modified: 2012-05-06
How can I assign  a value into my label that i dynamically created at runtime?

lblreadings.Text = indvalue
'creates the active reading boxes
        For intloop = 0 To ActiveCOM.Count - 1
            positionindex = 1
            lblreadings = New System.Windows.Forms.Label
            If intloop = 0 Then
                intx = 290
                inty = 85
            End If
            With lblreadings
                .Name = "lblreadings" & positionindex
                .Size = New System.Drawing.Size(100, 50)
                .Location = New System.Drawing.Point(intx, inty)
                .Text = "----4096-----"
                .Visible = True
            End With
 
            Me.Controls.Add(lblreadings)
            inty = inty + 50
            positionindex = positionindex + 1
        Next

Open in new window

0
Comment
Question by:cmdolcet
  • 4
  • 2
7 Comments
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24157662
If you mean you wish to change the Text of the label in a separate routine, use this....

    Me.Controls("lblreadings1").Text = "new text"

BTW, that will only work for VB.Net 2005 and later. In VB.Net 2003, you need to use the Controls.Find method....

    Me.Controls.Find("lblreadings1", True)(0).Text = "new text"

Wayne
0
 

Author Comment

by:cmdolcet
ID: 24157761
Thanks again I think it will work my only additional question is this every label I create down in the for loop has a name of "lblreadings" and the positionindex which I increment say for example I wanted to use the above code how would I assign the positionindex to a value

so that
'creates the active reading boxes
        For intloop = 0 To ActiveCOM.Count - 1
            positionindex = 1
            lblreadings = New System.Windows.Forms.Label
            If intloop = 0 Then
                intx = 290
                inty = 85
            End If
            With lblreadings
                .Name = "lblreadings" & positionindex
                .Size = New System.Drawing.Size(100, 50)
                .Location = New System.Drawing.Point(intx, inty)
                .Text = "----4096-----"
                .Visible = True
            End With
 
            Me.Controls.Add(lblreadings)
            inty = inty + 50
            positionindex = positionindex + 1
        Next

Open in new window

0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24157784
Me.Controls("lblreadings" & positionindex).Text = "new text"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24157804
>>how would I assign the positionindex to a value

I don't understand this bit, so if I'm wrong, can you try explaining again?
0
 

Author Comment

by:cmdolcet
ID: 24157902
what im trying to do is this my positionindex is declared in the CreateRuntimeControls() sub
what i need to do is show each individual text box an individual value in the TmrIndicatorBitValues_Tick sub
Private Sub CreateRuntimeControls()
        Dim chkbox As System.Windows.Forms.CheckBox
        Dim lblposition As System.Windows.Forms.Label
        Dim lblreadings As System.Windows.Forms.Label
        Dim btnbuttons As System.Windows.Forms.Button
        Dim intloop, intloop2, intx, inty As Integer
        Dim positionindex As Integer = 1
 
        'creates active comports on screen checkbox
        For intloop = 1 To _ActiveUSBPORTs
            chkbox = New System.Windows.Forms.CheckBox
            If intloop = 1 Then
                intx = 20
                inty = 85
            End If
            With chkbox
                .Name = "chkbox" & intloop
                .Size = New System.Drawing.Size(81, 17)
                .Location = New System.Drawing.Point(intx, inty)
                .Text = "Active Port"
                .Visible = True
 
            End With
            Me.Controls.Add(chkbox)
            inty = inty + 50
        Next
 
        'create position label on screen
        For intloop = 0 To ActiveCOM.Count - 1
            lblposition = New System.Windows.Forms.Label
            If intloop = 0 Then
                intx = 160
                inty = 85
            End If
            With lblposition
                .Name = "lblposition" & positionindex
                .Size = New System.Drawing.Size(81, 17)
                .Location = New System.Drawing.Point(intx, inty)
                .Text = "Position " & positionindex
                .Visible = True
            End With
            Me.Controls.Add(lblposition)
            inty = inty + 50
            positionindex = positionindex + 1
        Next
 
 
        'creates the active reading boxes
        For intloop = 0 To ActiveCOM.Count - 1
            positionindex = 1
            lblreadings = New System.Windows.Forms.Label
            If intloop = 0 Then
                intx = 290
                inty = 85
            End If
            With lblreadings
                .Name = "lblreadings" & positionindex
                .Size = New System.Drawing.Size(100, 50)
                .Location = New System.Drawing.Point(intx, inty)
                .Text = "----4096-----"
                .Visible = True
            End With
 
            Me.Controls.Add(lblreadings)
            inty = inty + 50
            positionindex = positionindex + 1
        Next
 
 
        'creates the active buttons
        For intloop = 0 To ActiveCOM.Count - 1
            positionindexbutton = 1
            btnbuttons = New System.Windows.Forms.Button
            If intloop = 0 Then
                intx = 460
                inty = 85
            End If
            With btnbuttons
                .Name = "btnbutton" & positionindexbutton
                .Size = New System.Drawing.Size(100, 30)
                .Location = New System.Drawing.Point(intx, inty)
                .Text = "View Information"
                .Visible = True
            End With
            AddHandler btnbuttons.Click, AddressOf Button_Click
            Me.Controls.Add(btnbuttons)
            inty = inty + 50
            positionindexbutton = positionindexbutton + 1
        Next
 
end sub
 
 
 
 Private Sub TmrIndicatorBitValues_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrIndicatorBitValues.Tick
        Dim position As Integer
        TmrIndicatorBitValues.Enabled = False
 
        For COMIndex = 0 To CurrCOMPort.Count - 1
            IndicatorPort = CurrCOMPort.Item(COMIndex)
            IndicatorPort.DiscardInBuffer()
            IndicatorCOMSetup.RequestProbeValues()
            position = COMIndex
 
            Select Case Position
                Case 0
                    Me.Controls("lblreadings1").Text = indvalue
                    '*********************************Sample loop for 1 inch indicator*******************************
                    'Checks to make sure 1 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1" Then
                        If preValue < indvalue And intarrayindex > 0 And Not preValue = 0 Then
                            tmrStageMove.Enabled = True
                        ElseIf (preValue - indvalue) = 1 Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 2
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf _BadResponse = True Then
                            tmrStageMove.Enabled = True
                            _BadResponse = False
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue & COMIndex
                            tmrStageMove.Enabled = True
                        End If
                        TmrIndicatorBitValues.Enabled = True
                    End If
 
                    '**********************Sample loop for 1/2 inch indicator**************************************
                    'Checks to make sure 1/2 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1/2" Then
                        If _BadResponse = True Then
                            _BadResponse = False
                            TmrIndicatorBitValues.Enabled = True
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue < indvalue And intarrayindex > 0 Then
                            If intarrayindex > 1270 Then
                                _ReadingArrayList3(intarrayindex) = indvalue
                                preValue = indvalue
                                tmrStageMove.Enabled = True
                                TmrIndicatorBitValues.Enabled = True
                            Else
                                TmrIndicatorBitValues.Enabled = True
                            End If
 
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
                            TmrIndicatorBitValues.Enabled = True
                        End If
                    End If
 
 
 
                Case 1
                    '*********************************Sample loop for 1 inch indicator*******************************
                    'Checks to make sure 1 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1" Then
                        If preValue < indvalue And intarrayindex > 0 And Not preValue = 0 Then
                            tmrStageMove.Enabled = True
                        ElseIf (preValue - indvalue) = 1 Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 2
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf _BadResponse = True Then
                            tmrStageMove.Enabled = True
                            _BadResponse = False
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue & COMIndex
                            tmrStageMove.Enabled = True
                        End If
                        TmrIndicatorBitValues.Enabled = True
                    End If
 
                    '**********************Sample loop for 1/2 inch indicator**************************************
                    'Checks to make sure 1/2 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1/2" Then
                        If _BadResponse = True Then
                            _BadResponse = False
                            TmrIndicatorBitValues.Enabled = True
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue < indvalue And intarrayindex > 0 Then
                            If intarrayindex > 1270 Then
                                _ReadingArrayList3(intarrayindex) = indvalue
                                preValue = indvalue
                                tmrStageMove.Enabled = True
                                TmrIndicatorBitValues.Enabled = True
                            Else
                                TmrIndicatorBitValues.Enabled = True
                            End If
 
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
                            TmrIndicatorBitValues.Enabled = True
                        End If
                    End If
 
                Case 2
                    '*********************************Sample loop for 1 inch indicator*******************************
                    'Checks to make sure 1 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1" Then
                        If preValue < indvalue And intarrayindex > 0 And Not preValue = 0 Then
                            tmrStageMove.Enabled = True
                        ElseIf (preValue - indvalue) = 1 Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 2
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf _BadResponse = True Then
                            tmrStageMove.Enabled = True
                            _BadResponse = False
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue & COMIndex
                            tmrStageMove.Enabled = True
                        End If
                        TmrIndicatorBitValues.Enabled = True
                    End If
 
                    '**********************Sample loop for 1/2 inch indicator**************************************
                    'Checks to make sure 1/2 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1/2" Then
                        If _BadResponse = True Then
                            _BadResponse = False
                            TmrIndicatorBitValues.Enabled = True
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue < indvalue And intarrayindex > 0 Then
                            If intarrayindex > 1270 Then
                                _ReadingArrayList3(intarrayindex) = indvalue
                                preValue = indvalue
                                tmrStageMove.Enabled = True
                                TmrIndicatorBitValues.Enabled = True
                            Else
                                TmrIndicatorBitValues.Enabled = True
                            End If
 
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
                            TmrIndicatorBitValues.Enabled = True
                        End If
                    End If
 
                Case 3
                    'Me.lblindicatorvalue4.Text = indvalue
                    '*********************************Sample loop for 1 inch indicator*******************************
                    'Checks to make sure 1 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1" Then
                        If preValue < indvalue And intarrayindex > 0 And Not preValue = 0 Then
                            tmrStageMove.Enabled = True
                        ElseIf (preValue - indvalue) = 1 Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 2
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf _BadResponse = True Then
                            tmrStageMove.Enabled = True
                            _BadResponse = False
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue & COMIndex
                            tmrStageMove.Enabled = True
                        End If
                        TmrIndicatorBitValues.Enabled = True
                    End If
 
                    '**********************Sample loop for 1/2 inch indicator**************************************
                    'Checks to make sure 1/2 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1/2" Then
                        If _BadResponse = True Then
                            _BadResponse = False
                            TmrIndicatorBitValues.Enabled = True
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue < indvalue And intarrayindex > 0 Then
                            If intarrayindex > 1270 Then
                                _ReadingArrayList3(intarrayindex) = indvalue
                                preValue = indvalue
                                tmrStageMove.Enabled = True
                                TmrIndicatorBitValues.Enabled = True
                            Else
                                TmrIndicatorBitValues.Enabled = True
                            End If
 
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
                            TmrIndicatorBitValues.Enabled = True
                        End If
                    End If
 
                Case 4
                    'Me.lblindicatorvalue5.Text = indvalue
                    '*********************************Sample loop for 1 inch indicator*******************************
                    'Checks to make sure 1 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1" Then
                        If preValue < indvalue And intarrayindex > 0 And Not preValue = 0 Then
                            tmrStageMove.Enabled = True
                        ElseIf (preValue - indvalue) = 1 Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 2
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf _BadResponse = True Then
                            tmrStageMove.Enabled = True
                            _BadResponse = False
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue & COMIndex
                            tmrStageMove.Enabled = True
                        End If
                        TmrIndicatorBitValues.Enabled = True
                    End If
 
                    '**********************Sample loop for 1/2 inch indicator**************************************
                    'Checks to make sure 1/2 Inch table values collected are al unique and spaced out even
                    If strTestType = "Indicator 1/2" Then
                        If _BadResponse = True Then
                            _BadResponse = False
                            TmrIndicatorBitValues.Enabled = True
                            Exit Sub
                        ElseIf preValue = indvalue Then
                            indvalue = indvalue - 1
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
 
                        ElseIf preValue < indvalue And intarrayindex > 0 Then
                            If intarrayindex > 1270 Then
                                _ReadingArrayList3(intarrayindex) = indvalue
                                preValue = indvalue
                                tmrStageMove.Enabled = True
                                TmrIndicatorBitValues.Enabled = True
                            Else
                                TmrIndicatorBitValues.Enabled = True
                            End If
 
                        Else
                            _ReadingArrayList3(intarrayindex) = indvalue
                            preValue = indvalue
                            tmrStageMove.Enabled = True
                            TmrIndicatorBitValues.Enabled = True
                        End If
                    End If
 
            End Select
        Next
 
    End Sub

Open in new window

0
 
LVL 1

Accepted Solution

by:
parul11183 earned 1000 total points
ID: 24158282
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24162437
cmdolcet,

How does the selected comment answer your question?? It doesn't even have anything to do with VB.Net!

Wayne

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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