Hey guys, im getting this error trying to when trying to import a txt file and use it as my combo box.
"Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
And here is the code It is occurring in PS (Im a rookie at VB so being as basic as possible would help :3 )
"Handles clause requires a WithEvents variable defined in the containing type or one of its base types."
And here is the code It is occurring in PS (Im a rookie at VB so being as basic as possible would help :3 )
Code:
Private Sub btnLoadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadData.Click
' The frmHurricane load event reads the hurricane text file
lblStats1.Text = ""
lblStats2.Text = ""
lblStats3.Text = ""
' Initialize an instance of the StreamReader object and declare variables
Dim objReader As IO.StreamReader
Dim strLocationAndNameOfFile As String = "E:\Visual Basics\WarnckeAssignment\hurricanes.txt"
Dim intFill As Integer
Dim intCount As Integer = 0
Dim strFileError As String = "The file is not available. Restart when the file is available."
' Verify the file exists
If IO.File.Exists(strLocationAndNameOfFile) Then
objReader = IO.File.OpenText(strLocationAndNameOfFile)
' Read the file line by line until the file is complete
Do While objReader.Peek <> -1
strYear(intCount) = objReader.ReadLine()
strNumber(intCount) = Convert.ToInt32(objReader.ReadLine())
intCount += 1
Loop
objReader.Close()
' The ComboBox object is filled with the years
For intFill = 0 To (strYear.Length - 1)
cboYear.Items.Add(strYear(intFill))
Next
Else
MsgBox(strFileError, , "Error")
Close()
End If
End Sub