Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB Script on an ASP

Posted on 1999-01-27
1
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
wpd earned 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

610 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