Solved

VB Script on an ASP

Posted on 1999-01-27
1
139 Views
Last Modified: 2010-05-03
I need to declare a global boolean variable, but this
'Global bInfo as Boolean' does not work.
0
Comment
Question by:DanielJenkins
1 Comment
 
LVL 2

Accepted Solution

by:
wpd earned 50 total points
ID: 1470952
In VBSCRIPT, unlike standard VB, variables don't have a type. Basically, they are all of type "variant".

Dim bInfo as Boolean ' works with VB, breaks in VBSCRIPT
Dim bInfo ' declares a Variant, works with VB & VBSCRIPT

Writing 'Dim x as ...' will always break in VBSCRIPT.
Note that you don't _have to_ explicitly declare variables. Doing so permits faster execution, though.

Also, there is the question of scope, as illustrated by your 'Global bInfo as ...'. In the latest version of VBSCRIPT, the scope of any variable (declared or not) is the ASP Page, unless it is declared in a function or sub, in which case the scope is limited to the function.

Dim x ' page-scope
x = 2

Sub foo ()
      Dim y ' lives inside of foo()
      y = 2 * x ' y equals 4
      .... ' do sth with y
End Sub

Sub bar()
      Dim x ' x is a local var
      x = 3 ' won't affect x which was declared at the page level
End Sub

Call bar
if x = 2 then ' condition is true
.
end if

Henceforth, there are no global variables in VBSCRIPT. You may however store variables at the session level, using :
 
Session("bInfo") = True ' available for all pages within the session

or at the application level :

Application("bInfo") = True ' available for all pages, all sessions/users, until the server is shut down.

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question