Forum Home
Press F1
 
Thread ID: 77172 2007-03-01 09:18:00 "Out-of-left-field" question for any ASP/VBScript Gurus ... davehartley (3487) Press F1
Post ID Timestamp Content User
529087 2007-03-01 09:18:00 Can anyone tell me where I can declare a Const? Can I do it anywhere? (As you can guess, I don't think I can!)

Let me embellish ... I've just done a website design which basically dynamically includes ASP snippets from files as needed. I'm using Server.Execute, as #include can't take a variable.

The problem is, in some ASP files I've dimensioned an array using a Const as the limit. And I'm getting errors because ... the thing I've declared a Const is being picked up as "not-a-Const!" :badpc:

I know I can put a Const in a #include ... but can I put it in a file that is #include'd in another that is then executed through Server.Execute? :confused: And do the Const's need to be declared "early" in the piece? Or anywhere?

Any guiding light would be much appreciated, as I can't seem to find much out there on this ... :help:
davehartley (3487)
529088 2007-03-02 08:32:00 (Bump) ... anyone? davehartley (3487)
529089 2007-03-02 09:31:00 I am not being rude, but that is a hell of a question. I did not understand a word of it. I reckon you will have to be patient & wait for a really knowledeable person to come along. Sorry. PJ Poppa John (284)
529090 2007-03-02 20:40:00 if I rememebr correctly
Constant should be declared as early as possible, I used to declare them first
Constant's value cant be changed

There are some ASP gurus here
Maybe if you posted the code snipit that is causing problem and give us the the error message also both those would help the gurus trouble shoot your code.

Sometimes entering the error message into google can reveal all sorts of informational gems
beama (111)
529091 2007-03-03 05:52:00 My humble apologies ... after doing some investigation, it turns out it's not the Const declaration giving me the problem, but using it to dimension an array :badpc:

Here 'tis:



<%
Const five = 5

dim fiveArray(five)
%>

I get this error:

Microsoft VBScript compilation error '800a0402'

Expected integer constant

/daveslaptop/testPage.asp, line 16

dim fiveArray(five)
--------------^

I, in my ignorance, thought declaring "five" as a Const makes it an integer constant ... which, in fact, it is, as I can use it later on in the code, and I get an error if I try and assign it a different value. What am I missing? :waughh:
davehartley (3487)
529092 2007-03-03 06:38:00 Constant are a value that does not and cannot be changed
assign another constant if you want a different value to a different varable
ie

dim six Const
six = five+1

been a while since Ive done any vbs scripting so check the syntax of the above
beama (111)
529093 2007-03-03 06:42:00 No, the problem is I've defined the constant but can't use it to dimension an array. If you look at my error above, it tells me I'm not using an integer constant ... when, in fact, I am! (Albeit one I've defined.) davehartley (3487)
529094 2007-03-03 07:10:00 from a bit of googling it appears that there is no data type of Const in vb scripting ( I maybe wrong here)
www.herongyang.com
sunsite.serc.iisc.ernet.in

you may have to do it the old way
assign a value to variable and ensure you don't change it
give it a name such as const

ie
dim Const = 5
beama (111)
529095 2007-03-03 07:19:00 Well ASP/VB isn't a language I'm familiar with, but what about this:

You have declared five as a constant, but you haven't said what type of constant. Why does VB have any reason to consider it an integer? If you don't declare the type, it will do its best to guess the type based on your syntax.

Can you instead declare it with something like this:

Const five = integer(5);

Obviously the syntax will probably wrong, as I don't know the language, but does ASP/VB have the capability to declare the constant type?
Erayd (23)
529096 2007-03-03 07:27:00 Well ASP/VB isn't a language I'm familiar with, but what about this:

You have declared five as a constant, but you haven't said what type of constant. Why does VB have any reason to consider it an integer? If you don't declare the type, it will do its best to guess the type based on your syntax.

Can you instead declare it with something like this:

Const five = integer(5);

Obviously the syntax will probably wrong, as I don't know the language, but does ASP/VB have the capability to declare the constant type?

good point

without declaring the data type I think VBS treats varaible of undeclaired type as a Variant

the syntax for variable declaration is given in the first link I gave above

asp (active server pages) any scripting language can be used
beama (111)
1 2