problem with VB.net array

I have to write words in a textbox(with multiline) in a form.
At the end of the word, the user have to enter and starts to type the next word. At the end the user have to type on a command button and all the words are written in a listbox. But every word have just one line in the listbox. I used this code but it don't work. Is there anyone who can help me??




Private Sub cmdDrukAf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDrukAf.Click
Dim strTekst As String
Dim a() As String
Dim nTeller As Long

Dim intAantal As Integer
Dim intTeller As Integer
Dim objLetter As Char

Dim strWoord As String
Dim strDeel As String
Dim intDeel As Integer
Dim intRechts As Integer

strWoord = txtInvoer.Text
intAantal = Len(strWoord)
nTeller = 0
Do
ReDim Preserve a(nTeller)
For intTeller = 0 To intAantal
objLetter = strWoord.Substring(intTeller, 1)

If objLetter = vbCrLf Then

strDeel = strWoord.Substring(intTeller, 4)
a(intDeel) = strDeel


Else
nTeller += 1
strDeel = Mid(strWoord, intTeller + 1)
End If

Next intTeller


Loop
For Each strDeel In a
lstInvoer.Items.Add(strDeel)
Next strDeel

End Sub
End Class

Comments

  • Hi,

    Here is a possibility.
    I put three controls on the form: Button1, TextBox1, ListBox1
    and added the following code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim a() As String
    Dim i As Integer

    If Not TextBox1.Text = String.Empty Then
    a = Split(TextBox1.Text, vbCrLf)
    For i = LBound(a) To UBound(a)
    ListBox1.Items.Add(a(i))
    Next
    End If
    End Sub

    Hope this helps,

    Chris

    : I have to write words in a textbox(with multiline) in a form.
    : At the end of the word, the user have to enter and starts to type the next word. At the end the user have to type on a command button and all the words are written in a listbox. But every word have just one line in the listbox. I used this code but it don't work. Is there anyone who can help me??
    :
    :
    :
    :
    : Private Sub cmdDrukAf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDrukAf.Click
    : Dim strTekst As String
    : Dim a() As String
    : Dim nTeller As Long
    :
    : Dim intAantal As Integer
    : Dim intTeller As Integer
    : Dim objLetter As Char
    :
    : Dim strWoord As String
    : Dim strDeel As String
    : Dim intDeel As Integer
    : Dim intRechts As Integer
    :
    : strWoord = txtInvoer.Text
    : intAantal = Len(strWoord)
    : nTeller = 0
    : Do
    : ReDim Preserve a(nTeller)
    : For intTeller = 0 To intAantal
    : objLetter = strWoord.Substring(intTeller, 1)
    :
    : If objLetter = vbCrLf Then
    :
    : strDeel = strWoord.Substring(intTeller, 4)
    : a(intDeel) = strDeel
    :
    :
    : Else
    : nTeller += 1
    : strDeel = Mid(strWoord, intTeller + 1)
    : End If
    :
    : Next intTeller
    :
    :
    : Loop
    : For Each strDeel In a
    : lstInvoer.Items.Add(strDeel)
    : Next strDeel
    :
    : End Sub
    : End Class
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion