Dear Sir/Madam,

I have created a sample program that dynamically created up to 7 numbers of Labels and Text Boxes. Here I want to add those numbers inputted by user on dynamically created text boxes. I have tried a lot but all are in vain. Please guide me to solve this problem.

I have attached my test program.

Recommended Answers

All 4 Replies

Dear Debasisdas,

Androidz has not got any solution yet.

I am posting whole codes of my project for easy reading. And if somebody want to see the project with form and control please download the attachment from my above post.

Dim WithEvents TxtBox As TextBox
Dim WithEvents LblLabel As Label
Dim NoOfControl As Integer
Dim A As Integer

Private Sub AddFromCreatedTextBox_Click()
'what will be the codes here
End Sub

Private Sub CmdLoadTextBox_Click()
Dim TopPosition As Integer

NoOfControl = Val(Trim(Text1.Text))

If NoOfControl <= 7 Then
    TopPosition = 3000

    For A = 1 To NoOfControl Step 1
        Set LblLabel = Me.Controls.Add("vb.Label", "DLabel" + Trim(Str(A)))
        With LblLabel
            .Left = 500
            .Top = TopPosition
            .Width = 2000
            .Height = 700
            .Visible = True
            .Caption = "Enter Number on Text Box"
            .DragMode = 0
        End With
        Set TxtBox = Me.Controls.Add("vb.TextBox", "TxtBox" + Trim(Str(A)))
        With TxtBox
            .Left = 3000
            .Top = TopPosition
            .Width = 1000
            .Height = 500
            .Visible = True
            .DragMode = 0
        End With
        TopPosition = TopPosition + 1000
    Next A

    MsgBox "You can't create here more than 7 controls"
    Exit Sub
End If

End Sub

I have got the result/solution from Microsoft Visual Basic Developer Center. The answer has given by respected sir "Calle Mellergardh". And the codes are ...

Private Sub AddFromCreatedTextBox_Click()
'what will be the codes here
Dim ctl As Control
    Dim num As Integer
    Dim total As Integer
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox And InStr(ctl.Name, "TxtBox") <> 0 Then
            num = Val(Trim(ctl.Text))
            total = total + num
        End If
    MsgBox total
End Sub
commented: thank you for shairing. +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.