REDIM PRESERVE array

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

REDIM PRESERVE array

Post by sal21 »

in a module have a public variable mio_array() as string

now i fill the array with:
...
AR=0
for i to ...

ReDim Preserve MIO_ARRAY(AR) As String
MIO_ARRAY(AR) = RS.Fields(0).Value & "-" & ITMX.SubItems(5)
AR = AR + 1

next i
...

is rquired to dim mio_array, or the statement ReDim Preserve MIO_ARRAY(AR) As String, dim the variable?

User avatar
HansV
Administrator
Posts: 78238
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: REDIM PRESERVE array

Post by HansV »

You need both:
- You cannot use ReDim Preserve if you haven't declared the array before that.
- In Redim Preserve, you must specify the new upper bound (AR).
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: REDIM PRESERVE array

Post by sal21 »

HansV wrote:
10 Jul 2020, 15:18
You need both:
- You cannot use ReDim Preserve if you haven't declared the array before that.
- In Redim Preserve, you must specify the new upper bound (AR).
ok
now i find in array with:

If InStr(Join(MIO_ARRAY), RS.Fields(0).Value) > 0 Then
STATO = "?"
End If

now ho to fill STATO with the element of array?

the array is similar

72-aaa
80-bbb
...
986-ccc

in this case RS.Fields(0).Value=72

i need STATO = "72-aaa"

other way are welcome :evilgrin:

note:
not possible duplicates in array

User avatar
HansV
Administrator
Posts: 78238
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: REDIM PRESERVE array

Post by HansV »

I'd use this:

Code: Select all

    Dim MIO_ARRAY2
    MIO_ARRAY2 = Filter(MIO_ARRAY, RS.Fields(0).Value)
    If UBound(MIO_ARRAY2) >= 0 Then
        STATO = MIO_ARRAY2(0)
    End If
Best wishes,
Hans