Help in my Visual Basic Program...just got stuck

I'm creating a Multiplayer LAN game in VB 2008

here is what I wanted to do

I created a textbox named txtbuttons.text. If I inputed a value, for example 23856 in the textbox.The Values will be distributed in different textboxes.

Value of txtbutton.text = 23856

2 will be distributed to txtAns.text
3 will be distributed to txtAns2.text
8 will be distributed to txtAns3.text
5 will be distributed to txtAns4.text
6 will be distributed to txtAns5.text

Your help will be very much Appreciated...Thx:)

5 Years
Discussion Span
Last Post by PutingPanday
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim numtoDisturbute As String
        numtoDisturbute = Trim(txtSource.Text)
        If numtoDisturbute.Length = 0 Then Exit Sub
        Dim arr As New List(Of String)

        For Each Cha As Char In numtoDisturbute

        For i As Integer = 0 To arr.Count - 1
            Dim text As String = arr.Item(i)
            Select Case i
                Case 0
                    TextBox1.Text = text
                Case 1
                    TextBox2.Text = text
                Case 2
                    TextBox3.Text = text
                Case 3
                    TextBox4.Text = text

            End Select


    End Sub

Simple way:

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim item As String = txtbuttons.text
	Dim tbs As TextBox() = {txtAns, txtAns2, txtAns3, txtAns4, txtAns5}
	For i As Integer = 0 To item.Length - 1
		tbs(i).Text = item(i).ToString()
End Sub
Votes + Comments
Good one.

Hi Mitja.
Thanks for above code. i got to learn something today :) My code also works but its not as simple as urs... :)
but what if user enters one extra digit? Will it handle the outof range exception?

Edited by Pgmer: n/a


Then plz mark thread as solved if it solved and if possible post ur code if u have any different approach other than two above.

Edited by Pgmer: n/a



I just use this code

AnsButton1.Text = txtButtonsAns.Lines(0).ToString

Edited by PutingPanday: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.