Visual Basic 6 Runtime 381 "Invalid Property Array Index" Error

I program programming, especially in Visual Basic. I only use VB6 because I have to use it for college and I am completely stuck.

I have a list in which I want to display the name of the radio, and then when I click on the name, I want it to put data in some text fields, it's simple, I know, but I don’t even know the full VB6 syntax, so I completely stuck, I asked my teacher, but he doesn’t help much.

This is the line highlighted when the debug button is clicked:

x = radCatList.ItemData(radCatList.ListIndex) 

This is the code for the enitre form, again it is very simple, and I barely know what I am doing most of this project is copy and paste:

 Option Explicit Private Sub Form_Load() Dim r As radioRec Dim radioChan As Integer Dim x As Integer x = 1 radioChan = FreeFile Open radioFile For Random As radioChan Len = radioLen Get radioChan, x, r Do While Not EOF(radioChan) radCatList.AddItem r.rModel radCatList.ItemData(radCatList.NewIndex) = x x = x + 1 Get radioChan, x, r Loop Close radioChan End Sub Private Sub radCatList_Click() Dim r As radioRec Dim radioChan As Integer Dim x As Integer radCatList.Clear x = radCatList.ItemData(radCatList.ListIndex) radioChan = FreeFile Open radioFile For Random As radioChan Len = radioLen Get radioChan, x, r channelTxt = r.rLicense licenseTxt = r.rLicense rangeTxt = r.rRange stockTxt.Text = r.rStock Close radioChan End Sub 
+4
source share
1 answer

is your listindex probably equal to -1 since the list is not selected yet?

view the following code

 '1 form with ' 1 listbox : name=List1 Option Explicit Private Sub Form_Load() Dim intIndex As Integer For intIndex = 0 To 10 List1.AddItem CStr(intIndex) List1.ItemData(intIndex) = intIndex * intIndex Next intIndex ShowData List1.ListIndex End Sub Private Sub Form_Resize() List1.Move 0, 0, ScaleWidth, ScaleHeight End Sub Private Sub List1_Click() ShowData List1.ListIndex End Sub Private Sub ShowData(intIndex As Integer) Dim strShow As String strShow = "Index:" & CStr(intIndex) If intIndex > -1 Then strShow = strShow & " Data:" & CStr(List1.ItemData(intIndex)) End If Caption = strShow End Sub 

so all you have to add is check if listindex is not -1

+4
source

All Articles