Overwrite a string from the middle

Total Post:183

 1131  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
        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.

  1. Post:604

    Re: Overwrite a string from the middle

    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)

        'Code to create textbox

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

      Modified On Mar-30-2018 03:23:37 AM



Enter your email address here always to be updated. We promise not to spam!