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

Split Array into textboxes

Hi,

I have an array, and I want to split the contence into textboxes. I have written some code to do so, but it won't work and I can't figure out what's wrong with it.

Could someone please help me with this

Dim bh As String
          Dim x As String

 For Each bh In z

         

            MsgBox(bh)
            If x = 0 Then
                TextBox1.Text = bh
                x = (x + 1)

            End If

            If x = 1 Then

                TextBox2.Text = bh
                x = (x + 1)
            End If

            If x = 2 Then
                TextBox3.Text = bh
                x = (x + 1)

            End If

            If x = 3 Then
                TextBox4.Text = bh
                x = (x + 1)

            End If

            If x = 4 Then
                TextBox5.Text = bh

                x = (x + 1)

            End If
        Next
FrodoBaggins
Newbie Poster
15 posts since Dec 2010
Reputation Points: 10
Solved Threads: 1
 

See if this helps.

'//----- Pre-requisites: 4 TextBoxes. -------\\
        Dim arTemp() As String = {"text 1", "text 2", "text 3", "text 4"}'// your Array.
        TextBox1.Text = arTemp(0)
        TextBox2.Text = arTemp(1)
        TextBox3.Text = arTemp(2)
        TextBox4.Text = arTemp(3)
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

Thanks for reply.
You asked what's inside the array in yr PM:

Whats in the array will always change, depending on the user's input on previous forms, but this is how it works:

I have a text file, with values in it, separated by slashes. eg: 1/2/3/4/

This file gets imported into vb, which splits it based on the location of the slashes, and writes the strings into an array

so in the array would be
1/
2/
3/
4/

I don't think that code would work, because the array is in the variable z, but i'll try it with a for each statement.
Hope this helps you
the name of the array is Z

FrodoBaggins
Newbie Poster
15 posts since Dec 2010
Reputation Points: 10
Solved Threads: 1
 

Since you mentioned that you have a File with just one line as my "test.txt" File,

1/2/3/4/

..see if this helps.

Dim myFile As String = "C:\test.txt" '// your File.
        If IO.File.Exists(myFile) Then '// check if File Exists.
            '// read Text from File and Split into Arrays by the "/" char.
            Dim z() As String = IO.File.ReadAllText(myFile).Split("/")
            TextBox1.Text = z(0) '// Array 1.
            TextBox2.Text = z(1) '// Array 2.
            TextBox3.Text = z(2) '// Array 3.
            TextBox4.Text = z(3) '// Array 4.
        End If
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

k that code worked, thanks a LOT! :)
It listed all the splits in the textboxes, as it should.


I accedentally marked yr first post as up, but it's yr last post that did the trick, so thanks.

Thanks

Marked as solved

FrodoBaggins
Newbie Poster
15 posts since Dec 2010
Reputation Points: 10
Solved Threads: 1
 

just a quick question/ observation
If x is declared as string how did you manage to compare it as integer
e.g:If x = 0 Then

Mariandi
Light Poster
43 posts since Nov 2009
Reputation Points: 22
Solved Threads: 5
 

This question has already been solved

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