Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2006, 01:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default Access Data stored in an array

Please help me figure out why I can not access the data stored in my array. Below is a snipet of my code.


'Under General

Dim intAirportCodeArray(5) as long ' Variable array to store 5 records



This is how I store the data in the array and it is working because I am able to display it.

Public sub loaddata()

   ' read record....till eof

      intAirportCodeArray(intRecordIndex) = rsAirport!Airport_ID
       rsAirport.movenext
       Label80.Caption = intAirportCodeArray(intRecordIndex)


    ' loop to next record to store data to next variable array


end sub


This is when I am retrieving the array so I can update the database. I keep getting 0 in all intAirportCodeArray array.

public sub updatetables()

    intmaxidx = 0

 If Not intmaxidx = intDepartIndex Then 'intdepartindex was
           populated previously
    For intIndex = 0 To intDepartIndex
      rsFlight!From_Airport_ID = intAirportCodeArray(intmaxidx)
      intmaxidx = intmaxidx + 1
      rsFlight.Update

    Next intIndex
  End If

end sub


Please let me know what I am missing or doing wrong. Did I declare or create my array correctly?

Thanks

 
Old October 5th, 2006, 01:13 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Your array is big enough to hold 6 records, not 5 . . .

I presume you say that the storage is working because
Code:
Label80.Caption = intAirportCodeArray(intRecordIndex)
displays the right data. Is that right?

I further presume that you believe your array is not working properly because when you examine the database after public sub updatetables() runs, and the data are not there. Is this correct?

If this is so, I would like to know what
Code:
public sub updatetables()

    If intDepartIndex <> 0 Then               ' intdepartindex was 
        For intIndex = 0 To intDepartIndex    ' populated previously
            Debug.Print intAirportCodeArray(intIndex)

            rsFlight!From_Airport_ID = intAirportCodeArray(intIndex)
            rsFlight.Update

        Next intIndex
    End If

End Sub
yields in the immediate window...
 
Old October 9th, 2006, 02:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

My answer to your first two questions are both yes. I pressume that I am able to store the data but not able to retrieve it because I might have something missing in my procedure to retrieve them. I also know that aside from these two procedures, storing and reading the data to and from the array, nothing in the program touches them or initializes them.

Your question, what yields in the immediate window? It's 1 and 17 since there were only 2 data stored in this array.



 
Old October 10th, 2006, 01:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

I did some debugging and I found where the array was getting dropped. My application is calling a procedure from another form. After it goes back to the current form, it is being dropped.

What I am doing is editing an existing travel record. I do this first when a user clicks the toolbar to edit it. I then call a form called frmTraveller to populate a listview item. Then, when the user selects which record to edit, he or she then calls a procedure called fillfields which is in a different form called frmTravel. This is where the array is getting populated and I can see that the array has records stored in it. As soon as the procedure fillfields is done and the focus is back to the frmTraveller, I use debug.print to display the contents once again. This time it's gone! Below is the code for the module modConnection, frmTraveller and frmTravel.


Thanks for your help.

 
Old October 10th, 2006, 02:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

Okay guys. Somebody was able to point out what I was doing wrong. I have my Arrays Declared both globally and on the form level. I have forgotten to take the one I declared on the form level when I put one globally.

Thanks for all your help






Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure versus Data Access Logic Componen AspNetGuy BOOK: Beginning ASP.NET 2.0 and Databases 0 June 26th, 2008 05:25 PM
Sending Array to Stored Procedure in ItemUpdating kevorkian ASP.NET 2.0 Basics 3 June 11th, 2008 08:54 AM
How access fields of objects stored in Array List rfinks VB How-To 2 July 11th, 2006 06:00 PM
Pass an Array as a Parameter to a Stored Procedure booksnore2 Oracle 0 August 31st, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.