Click to See Complete Forum and Search --> : Array Referencing and Loading:Part 2


gknierim
February 23rd, 2000, 01:01 PM
And now for part 2 --actually continuation of 1st part - new problem though.

Ok, after doing everything the other post talks about, this works great. Except...I realized another problem. My listbox is sorted differently than when I arranged my array. Therefore, when I click on a value in the listbox, I get the description based on the index number and not the description for the item selected in the listbox. Is there a way I can pass the value(text) selected in the listbox to the function instead of the control? Or is there a way to search the array for the value of the listbox.text and bring back the description?

I hope this is clear.

Johnny101
February 23rd, 2000, 01:55 PM
I'm not sure i understand. you are building the array based on the recordset. then you are going through the array sequentially, building the list in the combobox. I don't see how the indexes are getting messed up. but, if you are manually placing items from the array into the listbox in a different order you could stick the index of that item in the array into the ItemData property of that listitem:

for iCounter = 5 to 10
cboBox.AddItem gudtItemClassCode(iCounter).sMidWestDescription
cboBox.ItemData(cboBox.NewIndex) = iCounter
next iCounter




Then you could use this for the GetItemClass function instead:

public Function GetItemClassMidWest(cboBox as Control) as string
Dim iCounter as Integer

iCounter = cboBox.Itemdata(cboBox.ListIndex)
GetItemClassMidWest = gudtItemClassCode(iCounter).sMidWestCode

End Function




hope this helps,
John


John Pirkey
MCSD
www.ShallowWaterSystems.com

gknierim
February 23rd, 2000, 02:21 PM
Actually, I was populating the listbox with one database and then referencing the items in the list with another database. Basically I took the following code you gave me below:

public Function GetItemClassDesc(lstFieldName as Control) as string
Dim iCounter as Integer

iCounter = lstFieldName.ListIndex
GetItemClassDesc = gudtItemClassCode(iCounter).sDescription

End Function



and instead of using the index number of the item in the listbox that was passed, I took the value(text) of the item selected in the list box and searched the type for that value. The modified code looks like this:

public Function GetItemClassDesc(lstFieldName as Control) as string
Dim iCounter as Integer
Dim sFieldName as string
Dim blnFound as Boolean
Dim i as Integer

'iCounter = lstFieldName.ListIndex
sFieldName = lstFieldName.Text

blnFound = false
i = 0

Do Until blnFound
If gudtItemClassCode(i).sFieldName = sFieldName then
iCounter = i
blnFound = true
else
i = i + 1
End If
Loop

GetItemClassDesc = gudtItemClassCode(iCounter).sDescription

End Function



Maybe that might help understand things. After all is said and done, it works great. I would however like to use something besides 'blnFound' to check to exit the loop. Any suggestions?

Johnny101
February 23rd, 2000, 03:12 PM
Well, instead of using the boolean, you could do something like this:

Dim i as Integer
for i = LBound(gudtItemClassCode) to UBound(gudtItemClassCode)
If gudtItemClassCode(i).sFieldName = sFieldName then
iCounter = i
Exit for
End If
next i




Basically, it's the same thing, just one less variable. I don't know if this has any performance impacts, i kind of doubt it.

Good luck,
John

John Pirkey
MCSD
www.ShallowWaterSystems.com

gknierim
February 23rd, 2000, 03:20 PM
Yea, something like that!! Hee hee. Thanks.