473,397 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Dim inside Select case executes in any case?

aa
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps something
similar to break needs to be used?
Apr 23 '07 #1
14 2220
aa wrote:
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?
You can only declare a static array once. You need to use a dynamic array:

dim arr()
Select case q
Case "a"
ReDim arr(5)
Case "b"
ReDim arr(2)
end select

You can get the vbscript documentation here:
http://tinyurl.com/7rk6

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 23 '07 #2
aa
Thanks,
It looks like it should be ReDim at the first decalration

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:O6**************@TK2MSFTNGP02.phx.gbl...
aa wrote:
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?

You can only declare a static array once. You need to use a dynamic array:

dim arr()
Select case q
Case "a"
ReDim arr(5)
Case "b"
ReDim arr(2)
end select

You can get the vbscript documentation here:
http://tinyurl.com/7rk6

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Apr 23 '07 #3
aa wrote:
Thanks,
It looks like it should be ReDim at the first decalration
What makes you say that? It shouldn't. Start by declaring it with with Dim,
then use ReDim to redefine it. This really is well-covered in the
documentation ...
>
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:O6**************@TK2MSFTNGP02.phx.gbl...
>aa wrote:
>>Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?

You can only declare a static array once. You need to use a dynamic
array:

dim arr()
Select case q
Case "a"
ReDim arr(5)
Case "b"
ReDim arr(2)
end select

You can get the vbscript documentation here:
http://tinyurl.com/7rk6
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 23 '07 #4
aa
The reason I said that that initially I did exactly as you said - declared
it Dim
and then ReDim. As a result I got an error saing that the arrey cannot be
ReDimed for it decleared as a fixed length array.
When I changed to ReDim it worked

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:OO**************@TK2MSFTNGP06.phx.gbl...
aa wrote:
Thanks,
It looks like it should be ReDim at the first decalration

What makes you say that? It shouldn't. Start by declaring it with with
Dim,
then use ReDim to redefine it. This really is well-covered in the
documentation ...

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:O6**************@TK2MSFTNGP02.phx.gbl...
aa wrote:
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?

You can only declare a static array once. You need to use a dynamic
array:

dim arr()
Select case q
Case "a"
ReDim arr(5)
Case "b"
ReDim arr(2)
end select

You can get the vbscript documentation here:
http://tinyurl.com/7rk6
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Apr 23 '07 #5
aa
The main question however, was if ASP/VBS are designed so that Dim in Select
case is executed for each case?

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:OO**************@TK2MSFTNGP06.phx.gbl...
aa wrote:
Thanks,
It looks like it should be ReDim at the first decalration

What makes you say that? It shouldn't. Start by declaring it with with
Dim,
then use ReDim to redefine it. This really is well-covered in the
documentation ...

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:O6**************@TK2MSFTNGP02.phx.gbl...
aa wrote:
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?

You can only declare a static array once. You need to use a dynamic
array:

dim arr()
Select case q
Case "a"
ReDim arr(5)
Case "b"
ReDim arr(2)
end select

You can get the vbscript documentation here:
http://tinyurl.com/7rk6
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Apr 23 '07 #6
aa wrote:
The main question however, was if ASP/VBS are designed so that Dim in
Select case is executed for each case?
The answer to that is "no", as you discovered. The vbscript compiler
"hoists" variable declarations to the beginning of the procedure. There
is no conditional declaration.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Apr 23 '07 #7
aa wrote:
The reason I said that that initially I did exactly as you said -
declared it Dim
and then ReDim. As a result I got an error saing that the arrey
cannot be ReDimed for it decleared as a fixed length array.
Then you did not do exactly as I said. My example used a dynamic array,
not a fixed-length array.
When I changed to ReDim it worked
If you add "option explicit" to your script, you will realize what you
did: you redimmed a variable that had not been declared, causing the
compiler to declare one for you.

This is a fixed-length (static) array:
dim arr(3)

Static arrays cannot be redimmed.
Only dynamic arrays can be redimmed:

dim arr()
....
redim arr(5)

I know I'm sounding like a broken record, but the documentation does
cover this topic.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Apr 23 '07 #8
aa wrote:
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?
http://blogs.msdn.com/ericlippert/ar...18/159378.aspx

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Apr 23 '07 #9
aa
I discovered that "yes".
If it were "no" then wy code in my original message
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:OY**************@TK2MSFTNGP04.phx.gbl...
aa wrote:
The main question however, was if ASP/VBS are designed so that Dim in
Select case is executed for each case?

The answer to that is "no", as you discovered. The vbscript compiler
"hoists" variable declarations to the beginning of the procedure. There
is no conditional declaration.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Apr 23 '07 #10
aa wrote:
I discovered that "yes".
OK, I misread your question and answered "no" instead of "yes", but
supplied the correct explanation for the behavior.
If it were "no" then wy code in my original message
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Because both dim statements get "hoisted" to the beginning of the
procedure during compilation. Both statements. So at runtime, what gets
executed is:

Dim arr(5)
Dim arr(2) '---raises error
Select Case q
etc.

Again, there is no conditional declaration allowed in vbscript.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Apr 23 '07 #11
aa
So it looks like Dim is executed before other code on a page as if this
other code is not there. Therefore my Select case is stripped down to
Dim arr(5)
Dim arr(2)
"Dave Anderson" <NY**********@spammotel.comwrote in message
news:#O**************@TK2MSFTNGP05.phx.gbl...
aa wrote:
Code like this
=======================
Select case q
Case "a"
Dim arr(5)
Case "b"
Dim arr(2)
end select
=====================
returns an error saying variable arr redefined.
Should it be like that or an I using Select incorrectly? Perhaps
something similar to break needs to be used?

http://blogs.msdn.com/ericlippert/ar...18/159378.aspx

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use
of this email address implies consent to these terms.


Apr 23 '07 #12
top.
to
bottom
from
read
not
do
conversations
sentences,
Like
top-post.
not
do
Please

aa wrote:
>http://blogs.msdn.com/ericlippert/ar...18/159378.aspx
So it looks like Dim is executed before other code on a page as if
this other code is not there. Therefore my Select case is stripped
down to Dim arr(5)
Dim arr(2)
Not "executed", exactly, but you have the right idea.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Apr 23 '07 #13
aa
Dave, are you OK?
"Dave Anderson" <NY**********@spammotel.comwrote in message
news:OE**************@TK2MSFTNGP03.phx.gbl...
top.
to
bottom
from
read
not
do
conversations
sentences,
Like
top-post.
not
do
Please

aa wrote:
http://blogs.msdn.com/ericlippert/ar...18/159378.aspx
So it looks like Dim is executed before other code on a page as if
this other code is not there. Therefore my Select case is stripped
down to Dim arr(5)
Dim arr(2)

Not "executed", exactly, but you have the right idea.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use
of this email address implies consent to these terms.


Apr 24 '07 #14
aa
This is what I have. Thanks
Because both dim statements get "hoisted" to the beginning of the
procedure during compilation. Both statements. So at runtime, what gets
executed is:

Dim arr(5)
Dim arr(2) '---raises error
Select Case q
etc.

Again, there is no conditional declaration allowed in vbscript.

Apr 24 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
1
by: ST | last post by:
Hi, I'm trying to debug someone else's code, and I'm going thru this Select Case statement. I'm having problems with the "OTHER" case...in that when the first line of the case is false, it jumps...
0
by: Bob | last post by:
Hi, I have a very odd postgresql problem. I have some subqueries contained within a function which are looking for unrefernced data and then delete any rows that are found: CREATE OR...
5
by: Brian Tkatch | last post by:
Is there a way to do ORDER BY with DESC inside a CASE statement? That is, given more than one choice for an ORDER BY based on a CASE statement, but only one of the choices will also use DESC...
26
by: Alexander Korsunsky | last post by:
Hi! I have some code that looks similar to this: -------------------------------------------- char array = "abcdefghij"; for (int i = 0; i < 10; i++) {
3
by: Mehmet Yavuz S. Soyturk | last post by:
Hello, consider the next code: var obj = {}; with(obj) { var x = 10; } print(x); print(obj.x);
1
amitpatel66
by: amitpatel66 | last post by:
Hi, Is PLSQL Anonymous block allowed in CASE WHEN statement when CASE is used in SELECT statement. Check below code which executes but does not return anything: SELECT job, CASE WHEN job =...
0
by: Eraser | last post by:
Hi to all .NET guru guys... I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation....
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.