Re: shape range help
- From: "NickHK" <TungCheWah@xxxxxxxxxxx>
- Date: Fri, 15 Sep 2006 15:59:33 +0800
Peter,
I'm not familiar enough with the Shape.Range/ShapeRange collections etc (as
from our previous thread on these various collection) to be sure what is
expected as input. Hence, it's difficult to know the effects of these
various combinations we've discussed.
Next situation I come across involving something similar I will pay more
attention to these aspects and see if I can fathom anything further.
NickHK
"Peter T" <peter_t@discussions> wrote in message
news:u2QbdoJ2GHA.1304@xxxxxxxxxxxxxxxxxxxxxxx
Actually I'm getting a bit confused myself, especially with myinconsistent
results. I'm sure I've got lots of code with only the ReDim varr() thatpreviously
works just fine.
However I had replicated the both the OP's error and his fix with use of
brackets. However initial use of Dim() avoided use of brackets and he
reported same worked for him. The difference being Variant/Variant() and
Variant().
Regards,
Peter T
"NickHK" <k24@xxxxxxxxxxx> wrote in message
news:eBioE6A2GHA.1304@xxxxxxxxxxxxxxxxxxxxxxx
Peter,that
I can't repeat you experience. Using excel 2K also.
Everytime with ReDim only, I get a Variant()
I noticed some seeming unexpected behaviour with Variant/Variant() etc
at the time I put down to my coding, but now you have metioned this, Iwill
pay more attention to these situations in the future.¼¶¼g©ó¶l¥ó·s»D:uhA3atA2GHA.1288@xxxxxxxxxxxxxxxxxxxxxxx
NickHK
"Peter T" <peter_t@discussions>
In your your example the "Dim varr()" is not
required at all, as the ReDim
effective includes the initial Dim and the resize.
I am inconsistently getting different results. As I mentioned
NOTif
never in a session I don't do the initial Dim varr() then redim does
Butinclude the initial Dim the way you say, I get a Variant/Variant().
ifdifferences
youI
later comment out the initial Dim varr() next time the redim works as
say.
I'm testing in xl2000 at the moment, I recall there are some
fashion...notbetween xl97 & later versions with variant arrays & ReDim requiring /
variantrequiring the initial dim () .
Not sure where this is leading...Me neither <g>
Regards,
Peter
"NickHK" <k24@xxxxxxxxxxx> wrote in message
news:#85BeYA2GHA.1256@xxxxxxxxxxxxxxxxxxxxxxx
Peter,
In your your example the "Dim varr()" is not required at all, as the
ReDim
effective includes the initial Dim and the resize.
If you check the Locals for
Dim VarArray() As Variant
Dim Var As Variant
You see
Variant()
Variant/Empty
However, if comment out the Dims and rely on the Redims only, you see
Variant()
Variant()
Presumably because if you starting from a ReDim, then an array of
must be created.
Not sure where this is leading, but it seems applicable in a
evaluatedmethod.¼¶¼g©ó¶l¥ó·s»D:enLNFKA2GHA.4796@xxxxxxxxxxxxxxxxxxxxxxx
NickHK
"Peter T" <peter_t@discussions>
evaluationHi Nick,
Brackets do affect the the outcome of some statements.
I forget the exact details, but it something about forcing an
of
the code in the brackets and effecting the ByRef/ByVal passing
Indeed, passing a variable enclosed in brackets passes the
hencevalue
of the variable and not a pointer, quite useful to avoid a variable
returning changed and yet allow use of ByRef.
AFAIK enclosing any expression in brackets evaluates a result,
timedo -use
of
brackets converted the Variant/Variant() to a useable Variant().
What I don't understand though is why sometimes I find if I first
Dim varr()
Redim varr(0 to 3)
it works as expected but strangely later in the same session I no
longer
need to do the initial Dim varr(). IOW, if I don't do that first
Iuseable
get
Variant/Variant()
but if I do that first time, then later omit, I still get the
itmethod.evaluationVariant()
Regards,
Peter T
"NickHK" <k24@xxxxxxxxxxx> wrote in message
news:uI0WPw$1GHA.868@xxxxxxxxxxxxxxxxxxxxxxx
Brackets do affect the the outcome of some statements.
I forget the exact details, but it something about forcing an
of
the code in the brackets and effecting the ByRef/ByVal passing
test
Private Sub CommandButton1_Click()
Dim InputSample As String
InputSample = "Input"
Call ByRefEG(InputSample)
MsgBox InputSample
InputSample = "Input"
ByRefEG InputSample
MsgBox InputSample
InputSample = "Input"
ByRefEG (InputSample)
MsgBox InputSample
End Sub
Function ByRefEG(ByRef Sample As String) As String
Sample = "Output"
ByRefEG = Sample
End Function
I'm not sure if this has anything to do with your situation; looks
like
Peter may be on to something with the nature of the Variant.
NickHK
<semiopen@xxxxxxxxxxx>
???????:1158236770.147889.234690@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
The wierd thing is that, if I dispense with A altogether in my
"Moe"))subs and write:
Sub Test4()
Dim Stooges As ShapeRange
Set Stooges = Sheets(1).Shapes.Range(Array("Larry", "Curly",
ArrayStooges.Group
End Sub
It works fine. This is wierd since the documentation on VBA's
arrayfunction explicitly says that it returns a variant containing an
(as opposed to an array of variants)
When I have
Dim A as Varaint
A = Array("Larry", "Curly", "Moe")
A is *exactly* a variant containing an array - in other words,
coercionagrees with the return type of Array() - no implicit type
inacceptsor
anything (at least none documented).
Thus, it really does seem to be a bug in Shapes.Range() when it
a variant containing an array if fed directly in from the Array
function but balks at it if the variant containing an array is
asubs:
isdeclared variant variable (unless, mysteriously, enclosed in
parenthesis). But - with your (and Jim's) help - the work-around
*you*things,enclosingclear, so I won't worry about it. Excel is full of wierd quirks.
Thank you for your time
-semiopen
Peter T wrote:
<semiopen@xxxxxxxxxxx> wrote in message
news:1158233545.320167.51500@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Peter T wrote:
If you declare -
Dim A() As Variant iso Dim A As Variant
I think you'll find you don't need to evaluate the array by
in
brackets. see the difference in Locals
You (and Jim) are right in that context. To play around with
I
andcreated a new spreadsheet with three rectangles named Larry,
Curly
Moe (I like giving my shapes interesting names - how would
like
to be refered to as Human 12 ?) and wrote the following 3
you
Sub Test1()
Dim Stooges As ShapeRange
Dim A() As Variant 'an array of variants
A = Array("Larry", "Curly", "Moe")
Set Stooges = Sheets(1).Shapes.Range(A) 'works fine
Stooges.Group
End Sub
Sub Test2()
Dim Stooges As ShapeRange
Dim A As Variant 'just a variant
A = Array("Larry", "Curly", "Moe")
Set Stooges = Sheets(1).Shapes.Range(A) 'throws an error!
Stooges.Group
End Sub
Sub Test3()
Dim Stooges As ShapeRange
Dim A As Variant 'just a variant
A = Array("Larry", "Curly", "Moe")
Set Stooges = Sheets(1).Shapes.Range((A)) 'the error is gone!
Stooges.Group
End Sub
It seems to be an outright bug, no? Why should A <> (A) ? If
butcompare Test1 with Test3, maybe there is some sort of wierd
Microsoft
conservation of parenthesis law that I was unaware of.
-semiopen
Our recent posts sent at about the same time obviously crossed,
note
the
difference between
Variant() vs Variant/Variant()
Regards,
Peter T
<snip>
.
- References:
- shape range help
- From: semiopen
- Re: shape range help
- From: Jim Cone
- Re: shape range help
- From: semiopen
- Re: shape range help
- From: Jim Cone
- Re: shape range help
- From: semiopen
- Re: shape range help
- From: Jim Cone
- Re: shape range help
- From: semiopen
- Re: shape range help
- From: Peter T
- Re: shape range help
- From: semiopen
- Re: shape range help
- From: Peter T
- Re: shape range help
- From: semiopen
- Re: shape range help
- From: NickHK
- Re: shape range help
- From: Peter T
- Re: shape range help
- From: NickHK
- Re: shape range help
- From: Peter T
- Re: shape range help
- From: NickHK
- Re: shape range help
- From: Peter T
- shape range help
- Prev by Date: Re: Colors Shapes vs Cells (Excel 2007)
- Next by Date: Delete entire row if two cells are duplicate
- Previous by thread: Re: shape range help
- Next by thread: Re: shape range help
- Index(es):
Relevant Pages
|