Solved

VB Script on an ASP

Posted on 1999-01-27
1
138 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now