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:)

Recommended Answers

All 6 Replies

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
commented: Good one. +6

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?

oh thx for your replies;)...but I already did it myself.:twisted:

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.


I just use this code

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

Be a part of the DaniWeb community

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