PDA

View Full Version : [VB.NET] Array help


Matty919
04-27-2009, 11:21 PM
Two questions about arrays. How would I:

1. Print an array with characters in with comma seperators without knowing the number of elements of the array when printed.

2. When accepting input check if the input letter is already in the array.

EDIT: Another question, why doesn't this code work. It says "Warning 2 Variable 'words' is used before it has been assigned a value. A null reference exception could result at runtime. 81 21 HangmanReadfromfile" Im trying to assign values to words...



Dim words() As String
Dim counter As Integer = 0
Dim SR As StreamReader
Dim FS As FileStream
FS = New FileStream("C:\Items.txt", FileMode.Open)
SR = New StreamReader(FS)
Dim itm As Object
itm = SR.ReadLine()
While Not itm = Nothing
words(counter) = itm
counter += 1
itm = SR.ReadLine()
End While
SR.Close()
FS.Close()
Console.WriteLine(words)
Console.ReadLine()


Thanks

Mike_O
04-28-2009, 09:11 PM
Regarding question 1 and 2, take a look at object ArrayList.