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

Recommended Answers

All 5 Replies

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)
commented: Thanks for help, and solving my problem +0

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

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

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

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

commented: .very good observation.:) +12
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.