1

In asp classic and vbscript, you can declare a Const with a hexidecial value, and a date type value:

 Const C_LIGHTCYAN = &hCCFFEE
 Const C_STARTDATE = #1 JAN 2000#

But how can I declare currency, single or doubles data types?

 Const C_LONG = 1024 '# I want this to be a LONG, not an INT!

I'm sure I've seen something like Const C_LNG = L12345 or some other prefix/suffix combination for longs or doubles but can't find the source now

Guy
  • 9,720
  • 7
  • 38
  • 42

3 Answers3

0

While you can't declare data types in Windows Scripting (VBScript, ASP), you can assign a variable to become a type, then verify that variable's type. VBScript provides no type protections, so you're allowed to reassign a declared variable to a different type. This loose typing strategy is one root of problems.

Dim textVariable : textVariable = "Hello World!"
WScript.Echo TypeName(textVariable)
' Returns Text

Dim integerVariable : integerVariable = 6
WScript.Echo TypeName(integerVariable)
' Returns Integer

Dim objectVariable : set objectVariable = CreateObject("Scripting.Dictionary")
WScript.Echo TypeName(objectVariable)
' Returns Object

Some types require some brute force and trickery. The binary datatype is one example.

Dim generateData(1) : generateData(0) = &HFF
Dim mem : Set mem = CreateObject("System.IO.MemoryStream")
mem.SetLength(0)
mem.WriteByte (generateData(0))
Dim byteArray : byteArray = mem.ToArray()
'Returns a VB Style, "Byte()"   [Byte Array]
ndemarco
  • 209
  • 2
  • 12
0

You can't declare variables with data types in ASP just set the value in decleration, that should work fingers crossed.

I don't think there is currency type anyway. For double you can 1.00 etc.

dr. evil
  • 26,944
  • 33
  • 131
  • 201
  • 1
    There are currency data types: http://msdn.microsoft.com/en-gb/library/9e7a57cf(VS.85,loband).aspx I like "fingers crossed". I've gotfar too used to that that now... – Guy May 14 '09 at 09:55
0

Here is the CLng function for VBScript. But since you can't declare use a function for a constant declaration, and you can't re-assign to a constant, do you really have to use constants here?

MrChrister
  • 3,555
  • 5
  • 22
  • 34