Results 1 to 8 of 8
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Filtering 1-based array

    If I filter my 1-based variant array it becomes 0-based. But I have a situation where it's not always needing filtering


    so my check for Ubound > 0 fails if there only onw item in that array.
    Is there any 'elegant' fix or solution ? Thanks

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,417
    How about >= 0

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    I've made this complicated. I'm using a routine that puts some filename into a 1 based array.
    Then I filter the array to include (or remove) items matching some text.
    But this leaves the first item either in element 0 or sometimes element 1.
    Neither IsEmpty or Ubound seem to do what I want as they vary too.
    How can I get the first item, or nothing, reliably after filtering?

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,417
    You can refer to the array values via the index:

    if array(0) =
    if array(1) =

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    How are you building first array?

    Why use 1-based array?

    Why use array instead of recordset?
    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.

  6. #6
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    It's a collection of Filenames and the Function that builds it returns a 1-Based Array. I can't easily change that as other things use it.
    Recordset?? Not quite with you.
    I'm trying different things with the index as davegri suggested, But suspect if the array is empty... may need more.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Didn't know data was not in table.

    In my test, second array is always 0-based when it has elements, which seems odd with Option Base 1 in header.

    Could try an error handler. Set integer variable to UBound(ary2) or for value of ary(0), if it errors GoTo handler.
    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.

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    I was trying to avoid IFs for speed but this is all I can think of. I send in the filtered array and return the first item, or empty string.
    Seems ok but still testing.

    Code:
    Function ThePick(Arr) As String    If UBound(Arr) > -1 Then
            If Arr(0) > "" Then
                    ThePick = Arr(0)
                ElseIf UBound(Arr) > 0 Then
                    If Arr(1) > "" Then ThePick = Arr(1)
            End If
        End If
    End Function

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

Similar Threads

  1. Replies: 3
    Last Post: 02-26-2019, 07:27 PM
  2. Filtering based on selection
    By Naded in forum Access
    Replies: 5
    Last Post: 06-15-2018, 09:34 AM
  3. Filtering Query Based on Criteria
    By McArthurGDM in forum Queries
    Replies: 1
    Last Post: 11-20-2014, 03:31 PM
  4. Filtering based on form dates
    By cbh35711 in forum Programming
    Replies: 3
    Last Post: 03-13-2012, 11:46 AM
  5. Replies: 0
    Last Post: 07-30-2009, 12:40 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