Re: Handling ubound on an uninitialised array
From: Rob van Gelder (newsgroups_at_nojunkmail-vangelder.co.nz)
Date: 01/24/05
- Next message: Daniel: "Problem with hundredth of seconds"
- Previous message: Rob van Gelder: "Re: summing ranges"
- In reply to: keepITcool: "Re: Handling ubound on an uninitialised array"
- Next in thread: Mike NG: "Re: Handling ubound on an uninitialised array"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 Jan 2005 21:19:49 +1300
I gave a bad example but I think I'll just let it go.
I'd forgotten about the array dump to range - that's a nice feature.
-- Rob van Gelder - http://www.vangelder.co.nz/excel "keepITcool" <xrrcvgpbby@puryyb.ay> wrote in message news:xn0dxmo6j9y2u7i000keepitcoolnl@msnews.microsoft.com... > Rob, > > if you want to dump a simple array afaik excel doesnt care about upper > and lower bounds. > > > if you do want to change the upper and lower boundaries > (while keeping the same number of elements AND preserving the data.. > the variable must a declared as a variant not a variant array, > and you could do a simple redim preserve. > > I'll try to illustrate: > > > Sub Redimming() > Dim i, arr(), var, cpy > > ReDim var(10 To 19) > ReDim arr(10 To 19) > For i = LBound(arr) To UBound(arr) > var(i) = i > arr(i) = i > Next > > [a1:a5].Clear > 'dump the 10-based VARIANT > [a1].Resize(1, UBound(var) - LBound(var) + 1) = var > 'dump the 10-based VARIANT ARRAY > [a2].Resize(1, UBound(arr) - LBound(arr) + 1) = arr > > 'NOTE REDIM PRESERVE BOTH BOUNDS WORKS FOR A 'PLAIN' VARIANT ONLY > 'redim, dump the 1-based > ReDim Preserve var(1 To UBound(var) - LBound(var) + 1) > [a3].Resize(1, UBound(var) - LBound(var) + 1) = var > 'redim, dump the 0-based > ReDim Preserve var(0 To UBound(var) - LBound(var)) > [a4].Resize(1, UBound(var) - LBound(var) + 1) = var > > 'Copying ARR to a variant... and THEN resizing works > cpy = arr > ReDim Preserve cpy(0 To UBound(cpy) - LBound(cpy)) > [a5].Resize(1, UBound(cpy) - LBound(cpy) + 1) = cpy > > 'resizing ARR will not work > ReDim Preserve arr(0 To UBound(cpy) - LBound(cpy)) > > End Sub > > > > > > > > -- > keepITcool > | www.XLsupport.com | keepITcool chello nl | amsterdam > > > Rob van Gelder wrote : > >> It's tempting to argue this further, but I don't think I could >> provide a strong case to using zero-based indexing. >> I've only ever used zero-based - I've read no studies on bugcount >> for/against zero-based. I'm just not the guy to push the point :) >> >> The only thing I could think of is reusing the index variable.. eg. >> Copying your x array to a range might require two indexes where >> zero-based requires just one.
- Next message: Daniel: "Problem with hundredth of seconds"
- Previous message: Rob van Gelder: "Re: summing ranges"
- In reply to: keepITcool: "Re: Handling ubound on an uninitialised array"
- Next in thread: Mike NG: "Re: Handling ubound on an uninitialised array"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|