954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Visual Basic 2008 Textbox Values will be shown in different textbox

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.

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

PutingPanday
Newbie Poster
9 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 
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
            arr.Add(Cha)
        Next

        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

        Next

    End Sub
Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

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()
	Next
End Sub
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

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?

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

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

PutingPanday
Newbie Poster
9 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

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.

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

^ok

I just use this code

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

PutingPanday
Newbie Poster
9 posts since Aug 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: