Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to read a sentence from a textbox characterwise and as soon as the space character comes the prevoiusly occured characters are to put in a label. I am having problems in array data types.

Here is the code.

VB
Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click

        Dim count As Integer = 0
        Dim objreader As New System.IO.StreamReader(file_name.Text)

        TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf

        Dim myArray1() As Char = TextBox1.Text.ToCharArray()
        Dim myArray2 As List(Of Char) = New List(Of Char)


        For Each c As Char In myArray1
            If c <> " " Then
                myArray2.Add(c)
            Else
                id.Text = myArray2()           ' here is the issue
                Exit For
            End If
        Next

    End Sub
Posted
Updated 24-Sep-11 17:12pm
v2

Try changing the following line
VB
id.Text = myArray2()

To this
VB
id.Text = CStr(myArray2.ToArray())

Also, please do not cross post questions. I have seen your other question here[^]. You might also want to consider Luc's solution.
 
Share this answer
 
Comments
Abhinav S 25-Sep-11 0:04am    
Nice. 5.
walterhevedeich 25-Sep-11 2:31am    
Thanks Abhinav
You cannot directly assign an array to a textbox. You can assign an element of an array to a textbox (provided it is a string type).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900