Home > DeveloperSection > Forums > Overwrite a string from the middle
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    June-11-2013 5:30 AM

 VB.Net VB.Net 
Ratings:


 1 Reply(s)
 656  View(s)
Rate this:
Hi Developers, 

How to create textboxes? I need to know if there is a way to replace the end of a string with the new number.

my line of code as following

    While x <= tbnumberofitems
    Dim x As Integer = 0 ' looop count '
    Dim y As Integer = 1 ' name count'
    Dim label1name As String = "label"
    Dim textbox1name As String = "textbox"
    While x <= tbnumberofitems
        y = y + 1
        If x = 0 Then y = 1
        Convert.ToString(y)
        Dim label1 As New Label
        label1.Name = label1name & y

        'Code to create label box

        Dim textbox1 As New TextBox
        textbox1.Name = textbox1name & y

        'code to create text box

        x = x + 1
    End While

This is what I currently have. What I need now is a way to make it where when the loop runs the next time, it changes the name to textbox2 and label2 on 3rd loop label 3 and textbox 3, etc. If that is not clear enough what I am trying to do is make it where the numberofitems, make it 5, creates 5 labels and 5 textboxes through the program.

Any help on above is really appreciated.



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-12-2013 8:07 AM

Hi Ankita,

Basicly you can figure out as following

For x as Integer = 1 to tbnumberofitems

    'Code to create label

    Dim lbl As New Label
    lbl.Name = "label" & format(x)
    lbl.Location = New Point(10, x*20)
    Me.Controls.Add(lbl)

    'Code to create textbox

    Dim tb As New TextBox
    tb.Name = "TextBox" & format(x)
    tb.Location = New Point(100, x*20)
    Me.Controls.Add(tb)


Don't want to miss updates? Please click the below button!

Follow MindStick