I would be most grateful for help with the following code segment in Visual Basic 6.0.
Execution without the Error Handler gives Run-time error 424 Object required.
I have tried replacing strFileName with varFileName and strListBox with varListBox. I get the same error message.
I have also tried using val(varFileName) with again the same error..
lstMonth is a list box. Select Case has 6 options.
Thanks.
Regards,
Bill
Dim i As Integer
Dim strFileName As String
Dim varListBox As Variant
On Error GoTo ErrorHandler
For i = 1 To 6
Select Case i
Case "1"
strFileName = "MonthNames.dat"
varListBox = "lstMonth"
Case "2"
.
.
.
Open App.Path & "\" & strFileName For Input As #1
Do Until EOF(1)
Input #1, strFileName
With varListBox
.AddItem strFileName ' ERROR VB says Object Required
End With
Loop
Close #1
Next i
ErrorHandler:
Close #1
MsgBox ("Error in Sub PopulateListBoxs has been handled")
___________ From Watch Window ____________
Expression Value Type Context
i 1 Integer Form1.PopulateListBoxs
varFileName "Jan" Variant/String Form1.PopulateListBoxs
varListBox "lstMonth" Variant/String Form1.PopulateListBoxs
Execution without the Error Handler gives Run-time error 424 Object required.
I have tried replacing strFileName with varFileName and strListBox with varListBox. I get the same error message.
I have also tried using val(varFileName) with again the same error..
lstMonth is a list box. Select Case has 6 options.
Thanks.
Regards,
Bill
Dim i As Integer
Dim strFileName As String
Dim varListBox As Variant
On Error GoTo ErrorHandler
For i = 1 To 6
Select Case i
Case "1"
strFileName = "MonthNames.dat"
varListBox = "lstMonth"
Case "2"
.
.
.
Open App.Path & "\" & strFileName For Input As #1
Do Until EOF(1)
Input #1, strFileName
With varListBox
.AddItem strFileName ' ERROR VB says Object Required
End With
Loop
Close #1
Next i
ErrorHandler:
Close #1
MsgBox ("Error in Sub PopulateListBoxs has been handled")
___________ From Watch Window ____________
Expression Value Type Context
i 1 Integer Form1.PopulateListBoxs
varFileName "Jan" Variant/String Form1.PopulateListBoxs
varListBox "lstMonth" Variant/String Form1.PopulateListBoxs