Help with NewIndex Property 
Author Message
 Help with NewIndex Property

I am trying now to use the newindex property.  I have it listed in my
Form_load(), however, it appears to not increment correctly. Which results
in the cboName_Click event displaying the wrong information.  My code is
listed below.

Thanks Amy

Option Explicit
Private mstrConsumer(1 To 50, 1 To 6) As String

Private Sub cboName_Click()
    txtAddress1 = mstrConsumer(cboName.NewIndex, 1)
End Sub

Private Sub cmdExit_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Dim pstrName As String, pstrAddress1 As String
    Dim pstrAddress2 As String, pstrCity As String
    Dim pstrState As String, pstrZip As String
    Dim pstrCountry As String, pintCounter As Integer
    pintCounter = 1
    Open "c:\System\Consumer.txt" For Input As #1
    Do Until EOF(1) = True
        Input #1, pstrName, pstrAddress1, pstrAddress2, _
            pstrCity, pstrState, pstrZip, pstrCountry
         cboName.AddItem pstrName
         cboName.ItemData(cboName.NewIndex) = pintCounter
         mstrConsumer(pintCounter, 1) = pstrAddress1
         mstrConsumer(pintCounter, 2) = pstrAddress2
         mstrConsumer(pintCounter, 3) = pstrCity
         mstrConsumer(pintCounter, 4) = pstrState
         mstrConsumer(pintCounter, 5) = pstrZip
         mstrConsumer(pintCounter, 6) = pstrCountry
         pintCounter = pintCounter + 1
    Loop
    Close #1
End Sub



Fri, 15 Nov 2002 03:00:00 GMT  
 Help with NewIndex Property
Hi Amy:

Quote:
> Private Sub cboName_Click()
>     txtAddress1 = mstrConsumer(cboName.NewIndex, 1)
> End Sub

I believe you want to use the ItemData and NewIndex properties instead of
NewIndex, i.e.

     txtAddress1 = mstrConsumer(cboName.ItemData(cboName.ListIndex), 1)

Hope this helps,

--
Doug Marquardt
(Visual Basic MVP)
http://support.microsoft.com/support/mvp/



Fri, 15 Nov 2002 03:00:00 GMT  
 Help with NewIndex Property
try this for your click event

Private Sub cboName_Click()
    txtAddress1 = mstrConsumer(cboName.ListIndex, 1)
End Sub

Kirk

Quote:

>I am trying now to use the newindex property.  I have it listed in my
>Form_load(), however, it appears to not increment correctly. Which results
>in the cboName_Click event displaying the wrong information.  My code is
>listed below.

>Thanks Amy

>Option Explicit
>Private mstrConsumer(1 To 50, 1 To 6) As String

>Private Sub cboName_Click()
>    txtAddress1 = mstrConsumer(cboName.NewIndex, 1)
>End Sub

>Private Sub cmdExit_Click()
>    Unload Me
>End Sub

>Private Sub Form_Load()
>    Dim pstrName As String, pstrAddress1 As String
>    Dim pstrAddress2 As String, pstrCity As String
>    Dim pstrState As String, pstrZip As String
>    Dim pstrCountry As String, pintCounter As Integer
>    pintCounter = 1
>    Open "c:\System\Consumer.txt" For Input As #1
>    Do Until EOF(1) = True
>        Input #1, pstrName, pstrAddress1, pstrAddress2, _
>            pstrCity, pstrState, pstrZip, pstrCountry
>         cboName.AddItem pstrName
>         cboName.ItemData(cboName.NewIndex) = pintCounter
>         mstrConsumer(pintCounter, 1) = pstrAddress1
>         mstrConsumer(pintCounter, 2) = pstrAddress2
>         mstrConsumer(pintCounter, 3) = pstrCity
>         mstrConsumer(pintCounter, 4) = pstrState
>         mstrConsumer(pintCounter, 5) = pstrZip
>         mstrConsumer(pintCounter, 6) = pstrCountry
>         pintCounter = pintCounter + 1
>    Loop
>    Close #1
>End Sub



Sun, 08 Dec 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help with NewIndex Property

2. Why Outline control has no NewIndex property

3. Listbox ItemData NewIndex problem

4. How do I get round the missing itemdata / newindex problem

5. Workaround for .Newindex

6. ListBox controls and NewIndex

7. NewIndex Prop. of ListBox

8. Outline VBX, no NewIndex

9. Outline control, itemdata and no Newindex

10. NewIndex and dbListBox ???

11. Using newindex at combo

12. NewIndex - need advice

 

 
Powered by phpBB® Forum Software