Home All Groups Group Topic Archive Search About

newbie problem with array

Author
5 Feb 2006 9:45 AM
eejit
This is VBNET2005

I feel like I'm missing something really obvious here.

I keep getting the error "Value of type 'string' cannot be converted
to '1 dimensional array of string'"


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click




        Dim inputstream As New
System.IO.StreamReader("c:\testfile.txt")

        Dim line As String

        line = inputstream.ReadLine()

        Dim testarray() As String = Split(line)

        TextBox1.Lines = testarray(1)

        inputstream.Close()

    End Sub
End Class


Any help appreciated.

eejit

Author
5 Feb 2006 11:19 AM
Cor Ligthert [MVP]
EEjit,

I think that you can do
>        Dim testarray() As String = Split(line)
>
>        TextBox1.Lines = testarray(1)
Textbox1.text = testarray(1)
or
Textbox1.lines = testararray.length

http://msdn2.microsoft.com/en-us/library/hz0yf4h5(en-US,VS.80).aspx

I hope this helps,

Co
Author
6 Feb 2006 6:44 PM
Chris Dunaway
Cor Ligthert [MVP] wrote:
> Textbox1.lines = testararray.length
>

This will result in an error as the Lines property of the TextBox is an
array of strings and not an integer.
Author
6 Feb 2006 9:34 PM
Cor Ligthert [MVP]
Chris,

> This will result in an error as the Lines property of the TextBox is an
> array of strings and not an integer.

I was once searching for that lines property because it is in a mater of way
the equivalent to the multiline option. I could not find it anymore. This
showes that it was not deleted, however completely removed from my memory.

Thanks for pointing me on this.

:-)

Cor
Author
5 Feb 2006 12:00 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"eejit" <ee***@canada.com> schrieb:
> I keep getting the error "Value of type 'string' cannot be converted
> to '1 dimensional array of string'"
>
>
> Public Class Form1
>
>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles Button1.Click
>
>
>
>
>        Dim inputstream As New
> System.IO.StreamReader("c:\testfile.txt")
>
>        Dim line As String
>
>        line = inputstream.ReadLine()
>       
>        Dim testarray() As String = Split(line)
>
>        TextBox1.Lines = testarray(1)

\\\
Me.TextBox1.Lines = testarray
///

- or -

\\\
Me.TextBox1.Text = testarray(1)
///

depending on what you want to archieve.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
5 Feb 2006 8:41 PM
eejit
On Sun, 5 Feb 2006 13:00:56 +0100, "Herfried K. Wagner [MVP]"
<hirf-spam-me-here@gmx.at> wrote:

Show quoteHide quote
>"eejit" <ee***@canada.com> schrieb:
>> I keep getting the error "Value of type 'string' cannot be converted
>> to '1 dimensional array of string'"
>>
>>
>> Public Class Form1
>>
>>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
>> As System.EventArgs) Handles Button1.Click
>>
>>
>>
>>
>>        Dim inputstream As New
>> System.IO.StreamReader("c:\testfile.txt")
>>
>>        Dim line As String
>>
>>        line = inputstream.ReadLine()
>>       
>>        Dim testarray() As String = Split(line)
>>
>>        TextBox1.Lines = testarray(1)
>
>\\\
>Me.TextBox1.Lines = testarray
>///
>
>- or -
>
>\\\
>Me.TextBox1.Text = testarray(1)
>///
>
>depending on what you want to archieve.


Thankss that clears it up. Not sure what I was thinking.

eejit