Solved

VB Script on an ASP

Posted on 1999-01-27
1
137 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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now