CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2000
    Posts
    264

    Array Referencing and Loading:Part 2

    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.






  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Array Referencing and Loading:Part 2

    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
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Jan 2000
    Posts
    264

    Re: Array Referencing and Loading:Part 2

    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?



  4. #4
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Array Referencing and Loading:Part 2

    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
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  5. #5
    Join Date
    Jan 2000
    Posts
    264

    Re: Array Referencing and Loading:Part 2

    Yea, something like that!! Hee hee. Thanks.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured