Re: how to create an Array with parametrized name?
Hi Al,
A few responses interspersed below. I messed this up at the outset,
however, by an error in the air code that I posted.
I posted:
sub ...
execute "dim " & sVarName & "()"
The above works within Execute's intended parameters and just creates a
*local* array that goes out of scope when the Sub is exited, and so does the
OP no good. My bad. Should have been:
sub ...
execute "redim " & sVarName & "(0)"
This would take advantage of the undocumented operation and, because the
variable doesn't exist, would be create a new *global* array that could then
be legitimately Redimmed as necessary in the main script. This is what the
OP needed. What's worse is that I already use a correct version of this in
a routine in my library version of MH's IEPipe method (a non-visible IeApp
window used to pass data between multiple running scripts). Just screwed up
the posted air code.
| > and unintended.
|
| That's *their* problem. A more important question is: "Is it *expected*"
to
| which my answer is "Yes". A secondary question is: "will this departure
from
| a <fixed source> model be completely straightforward ", to which my answer
is
| "obviously not".
The fact that it doesn't error out on an uninitiated variable under Option
Explicit is unexpected. It also reduces the usefulness of the Execute
function for articulate error-trapping routines, for which it otherwise
ideally suited.
| > That's the only reason that it would work for
| > the OP in this situation and in the example that I gave.
|
| ... the reason it works is, well, that is how it works. It doesn't work
| because it is a bug, but because the underlying code does what it does.
The
| fact that this was unintended by the developers is really beside the
point.
Correct - see my correction to my air code above. This was my initial error
in using "dim" instead or "redim". The original code did not make use of
the unintended capabilities.
| > When I first
| > stumbled on this behavior over a year ago, Michael Harris verified the
| > operation and verified with Eric Lippert (who apparently wrote the
execute
| > code) that the behavior is both unintended and unlikely to change.
|
| Unintended: their mistake; unlikely to change: score one for platform
| stability.
Well, I think this is just because WSH 5.6 is unlikely to change, with no
further development (at least on the VBS side).
| > (from MH post)
| >
| > "I checked with Eric Lippert (who wrote the Execute and ExecuteGlobal
| > implementation code)...
| >
| > What you observe is actually a bug and unintended behavior.
|
| I disagree :-) It is only a bug if the behaviour was intended NOT to
| happen. Just because they missed a side effect of their own code
(especially
| one that has some specific uses), they should not go dissing themselves
over
| their oversight ;-)
Well, it does create anomalies. For example, if you were to call an
undefined function or sub without arguments, it does not error out, but
creates them as global variables.
In a different thread with MH, he pointed out that unintended and
undocumented effects may get changed in later versions, making previously
good script error-prone. Now that WSH seems to have no further development,
however, all the undocumented effects may be fair game - execute, omitted
user-defined procedure arguments, error scoping, etc. ;-)
| > Execute within
| > a procedure is *not* supposed to create a variable with global scope.
He
| > also noted that this is probably something that will never get fixed
| ;-)..."
| I consider the related documentation to be in error (or at least
misleading)
| in this respect, probably because it was written before executeglobal was
| implemented. One specific error in the definition of executeglobal is
shown
| in the extract below, highlighted in ALL CAPS.
Per MH, Eric Lippert wrote the code for both functions. As we all know,
however, documentation tends to get written in the beta stages and never
changed.
| I believe the paragraph and disbelieve the endline comments, both because
| that makes sense based on what EXECUTEGLOBAL means, and because, well,
that
| is actually how it works. This also indicates that the writers of the
| documentation were, like me, of the opinion that it was *expected* to
create
| a variable with global scope.
Except that it doesn't foresee the variable *error* situation. (I.e.,
creating an unintended new variable instead of erroring out.)
Regards,
Joe Earnest
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03
Hi Al,
A few responses interspersed below. I messed this up at the outset,
however, by an error in the air code that I posted.
I posted:
sub ...
execute "dim " & sVarName & "()"
The above works within Execute's intended parameters and just creates a
*local* array that goes out of scope when the Sub is exited, and so does the
OP no good. My bad. Should have been:
sub ...
execute "redim " & sVarName & "(0)"
This would take advantage of the undocumented operation and, because the
variable doesn't exist, would be create a new *global* array that could then
be legitimately Redimmed as necessary in the main script. This is what the
OP needed. What's worse is that I already use a correct version of this in
a routine in my library version of MH's IEPipe method (a non-visible IeApp
window used to pass data between multiple running scripts). Just screwed up
the posted air code.
| > and unintended.
|
| That's *their* problem. A more important question is: "Is it *expected*"
to
| which my answer is "Yes". A secondary question is: "will this departure
from
| a <fixed source> model be completely straightforward ", to which my answer
is
| "obviously not".
The fact that it doesn't error out on an uninitiated variable under Option
Explicit is unexpected. It also reduces the usefulness of the Execute
function for articulate error-trapping routines, for which it otherwise
ideally suited.
| > That's the only reason that it would work for
| > the OP in this situation and in the example that I gave.
|
| ... the reason it works is, well, that is how it works. It doesn't work
| because it is a bug, but because the underlying code does what it does.
The
| fact that this was unintended by the developers is really beside the
point.
Correct - see my correction to my air code above. This was my initial error
in using "dim" instead or "redim". The original code did not make use of
the unintended capabilities.
| > When I first
| > stumbled on this behavior over a year ago, Michael Harris verified the
| > operation and verified with Eric Lippert (who apparently wrote the
execute
| > code) that the behavior is both unintended and unlikely to change.
|
| Unintended: their mistake; unlikely to change: score one for platform
| stability.
Well, I think this is just because WSH 5.6 is unlikely to change, with no
further development (at least on the VBS side).
| > (from MH post)
| >
| > "I checked with Eric Lippert (who wrote the Execute and ExecuteGlobal
| > implementation code)...
| >
| > What you observe is actually a bug and unintended behavior.
|
| I disagree :-) It is only a bug if the behaviour was intended NOT to
| happen. Just because they missed a side effect of their own code
(especially
| one that has some specific uses), they should not go dissing themselves
over
| their oversight ;-)
Well, it does create anomalies. For example, if you were to call an
undefined function or sub without arguments, it does not error out, but
creates them as global variables.
In a different thread with MH, he pointed out that unintended and
undocumented effects may get changed in later versions, making previously
good script error-prone. Now that WSH seems to have no further development,
however, all the undocumented effects may be fair game - execute, omitted
user-defined procedure arguments, error scoping, etc. ;-)
| > Execute within
| > a procedure is *not* supposed to create a variable with global scope.
He
| > also noted that this is probably something that will never get fixed
| ;-)..."
| I consider the related documentation to be in error (or at least
misleading)
| in this respect, probably because it was written before executeglobal was
| implemented. One specific error in the definition of executeglobal is
shown
| in the extract below, highlighted in ALL CAPS.
Per MH, Eric Lippert wrote the code for both functions. As we all know,
however, documentation tends to get written in the beta stages and never
changed.
| I believe the paragraph and disbelieve the endline comments, both because
| that makes sense based on what EXECUTEGLOBAL means, and because, well,
that
| is actually how it works. This also indicates that the writers of the
| documentation were, like me, of the opinion that it was *expected* to
create
| a variable with global scope.
Except that it doesn't foresee the variable *error* situation. (I.e.,
creating an unintended new variable instead of erroring out.)
Regards,
Joe Earnest
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 09-23-03
Comment