Thursday, July 30, 2009

Need help inVB express 2005 - program not working?

Public Class ColorsForm





'program Colors on page 324. Needs to create an array with upper bound of 50 and then increase the size of the array





' by 10 elements whenever it runs out of space to store the colors.





' Need to figure out how to increase the size of the array when the program is reading a file and runs out of room





Dim Colors(50) As String





Dim reccount As Integer





Private Sub ColorsForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load





Dim i As Integer = -1





Dim sr As IO.StreamReader = IO.File.OpenText("c:\DOCUMENTS and Settings\COLORS.txt")





Do While (sr.Peek %26lt;%26gt; -1)





i += 1





Colors(i) = sr.ReadLine





Loop





sr.Close()





End Sub





Private Sub brnColors_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnColors.Click





lstColors.Items.Clear()





For i As Integer = 0 To 50


If (Colors(i).Substring(0, 1) = txtState.Text) Then


lstColors.Items.Add(Colors(i))


End If


Next


End Sub





End Class

Need help inVB express 2005 - program not working?
You can try using the resize function.


http://msdn2.microsoft.com/en-us/library...





But I would suggest using an array list.


http://msdn2.microsoft.com/en-us/library...





You have much better control over your array.


No comments:

Post a Comment