none
How to read from each line in a multiline textbox ? RRS feed

  • Question

  • Hello every one,

    i have this 23 line in textbox

    and i have 23 texbox

    how to get first line  AED 191  an set it to textbox1

    and second  line is AED 214 and set it to textbox2

    until last line

    AED 191 
    AED 214 
    AED 259 
    AED 305 
    AED 218 
    AED 241 
    AED 287 
    AED 332 
    AED 228 
    AED 273 
    AED 319 
    AED 319 
    AED 319 
    AED 419 
    AED 523 
    AED 400 
    AED 555 
    AED 692 
    AED 419 
    AED 573 
    AED 710 
    AED 205 
    AED 205 
    
    
    thanks in advance


    Friday, August 30, 2019 4:07 PM

Answers

  • Hi

    Here is some simple code that will do it. NOTE: there are many things that would need to be taken account of which this example doesn't - eg clicking the button a second and subsequent times will just add further TB to the list, there would need to be a set of Handlers created if the User needs to interact with the new TB, exception handling  - etc etc etc.

    I just added the data in the Designer for this example, yours would come from the Web table you mentioned before.

    *

    This is an image of the test project Form1, followed by the code

    ' Form1 with TextBox2 containing
    ' the list of items (would be better
    ' to use a List(Of String) intead)
    ' and a Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		Dim x As Integer = TextBox2.Left + TextBox2.Width + 4
    		Dim y As Integer = 4
    		For Each s As String In TextBox2.Lines
    			Dim tb As New TextBox
    			With tb
    				.Location = New Point(x, y)
    				.Size = New Size(100, 30)
    				.Text = s
    				x += .Size.Width + 4
    				If x > ClientRectangle.Width - .Size.Width - 4 Then
    					x = TextBox2.Left + TextBox2.Width + 4
    					y += tb.Height + 4
    				End If
    				Controls.Add(tb)
    			End With
    		Next
    	End Sub
    End Class


    Regards Les, Livingston, Scotland


    Friday, August 30, 2019 4:27 PM

All replies

  • Hi

    Here is some simple code that will do it. NOTE: there are many things that would need to be taken account of which this example doesn't - eg clicking the button a second and subsequent times will just add further TB to the list, there would need to be a set of Handlers created if the User needs to interact with the new TB, exception handling  - etc etc etc.

    I just added the data in the Designer for this example, yours would come from the Web table you mentioned before.

    *

    This is an image of the test project Form1, followed by the code

    ' Form1 with TextBox2 containing
    ' the list of items (would be better
    ' to use a List(Of String) intead)
    ' and a Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		Dim x As Integer = TextBox2.Left + TextBox2.Width + 4
    		Dim y As Integer = 4
    		For Each s As String In TextBox2.Lines
    			Dim tb As New TextBox
    			With tb
    				.Location = New Point(x, y)
    				.Size = New Size(100, 30)
    				.Text = s
    				x += .Size.Width + 4
    				If x > ClientRectangle.Width - .Size.Width - 4 Then
    					x = TextBox2.Left + TextBox2.Width + 4
    					y += tb.Height + 4
    				End If
    				Controls.Add(tb)
    			End With
    		Next
    	End Sub
    End Class


    Regards Les, Livingston, Scotland


    Friday, August 30, 2019 4:27 PM
  • i appreciate you a lot
    Friday, August 30, 2019 4:44 PM