?
Solved

VB Script on an ASP

Posted on 1999-01-27
1
Medium Priority
?
142 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses

801 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