Results 1 to 5 of 5
  1. #1
    ts_hunter is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    30

    Problem with function to increment array index

    I have two sections of code below. I would like to reference the array like I have it written in the first section of code. However that does not work. The second code works, but I would like to do it the other way. Is there something I am missing in the first section that causes the 'i' variable to not retain its value?



    Click image for larger version. 

Name:	code2.JPG 
Views:	11 
Size:	34.5 KB 
ID:	19114
    -------------------------------------


    Click image for larger version. 

Name:	code1.JPG 
Views:	11 
Size:	29.2 KB 
ID:	19115

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    strings(0) = "A"
    strings(1) = "B"
    For i = 0 to Ubound(strings)
    Debug.Print strings(i)
    Next
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ts_hunter is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    30
    Quote Originally Posted by June7 View Post
    strings(0) = "A"
    strings(1) = "B"
    For i = 0 to Ubound(strings)
    Debug.Print strings(i)
    Next
    Yes, I know about that method. But I am curious about why my #1 section of code doesn't work. Is there a way to make it work?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,959
    The first procedure does not increment the public variable i. It never changes from 0. Step debug and you will see that. It needs to be incremented somewhere - either in the sub or the function. Could add this line to the function: i = nexti
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ts_hunter is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    30
    Click image for larger version. 

Name:	D1.JPG 
Views:	6 
Size:	28.8 KB 
ID:	19118

    This works now that I added ' i = nexti'. I am using this for referencing indexes of an Excel spreadsheet, this function will clean up alot of code where I am doing i = i +1 and j = j + 1 where i and j are the cell indexes. THANKS.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. st deviation function on array
    By registoni in forum Programming
    Replies: 2
    Last Post: 09-09-2013, 04:00 AM
  2. Replies: 6
    Last Post: 05-31-2013, 07:46 PM
  3. Replies: 1
    Last Post: 07-30-2012, 02:47 PM
  4. Having Trouble Returning Array from Function
    By NigelS in forum Programming
    Replies: 8
    Last Post: 08-15-2011, 07:12 AM
  5. INNER JOIN to a split(array) function?
    By kman42 in forum Queries
    Replies: 8
    Last Post: 05-09-2011, 01:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums