Thursday, July 30, 2009

Need help in VB express 2005! code won't run?

Public Class Form1





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





End Sub


End Class


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 btnColors_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 in VB express 2005! code won't run?
It appears that you have two End Class statements for your forms code.





Public Class Form1





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





End Sub


End Class '****** this should be the last line


Public Class ColorsForm








Also you should place your variable declarations immediately after "Public Class Form1" followed by Subs and Functions.


No comments:

Post a Comment