TechNet
Products
IT Resources
Downloads
Training
Support
Products
Windows
Windows Server
System Center
Microsoft Edge
Office
Office 365
Exchange Server
SQL Server
SharePoint Products
Skype for Business
See all products »
Resources
Channel 9 Video
Evaluation Center
Learning Resources
Microsoft Tech Companion App
Microsoft Technical Communities
Microsoft Virtual Academy
Script Center
Server and Tools Blogs
TechNet Blogs
TechNet Flash Newsletter
TechNet Gallery
TechNet Library
TechNet Magazine
TechNet Wiki
Windows Sysinternals
Virtual Labs
Solutions
Networking
Cloud and Datacenter
Security
Virtualization
Updates
Service Packs
Security Bulletins
Windows Update
Trials
Windows Server 2016
System Center 2016
Windows 10 Enterprise
SQL Server 2016
See all trials »
Related Sites
Microsoft Download Center
Microsoft Evaluation Center
Drivers
Windows Sysinternals
TechNet Gallery
Training
Expert-led, virtual classes
Training Catalog
Class Locator
Microsoft Virtual Academy
Free Windows Server 2012 courses
Free Windows 8 courses
SQL Server training
Microsoft Official Courses On-Demand
Certifications
Certification overview
Special offers
MCSE Cloud Platform and Infrastructure
MCSE: Mobility
MCSE: Data Management and Analytics
MCSE Productivity
Other resources
Microsoft Events
Exam Replay
Born To Learn blog
Find technical communities in your area
Azure training
Official Practice Tests
Support options
For business
For developers
For IT professionals
For technical support
Support offerings
More support
Microsoft Premier Online
TechNet Forums
MSDN Forums
Security Bulletins & Advisories
Not an IT pro?
Microsoft Customer Support
Microsoft Community Forums
Sign in
Home
Library
Wiki
Learn
Gallery
Downloads
Support
Forums
Blogs
Resources For IT Professionals
United States (English)
Россия (Pусский)
中国(简体中文)
Brasil (Português)
Skip to locale bar
Post an article
Translate this page
Powered by
Microsoft® Translator
Wikis - Page Details
First published by
Craig Landis
(6Microsof)
When:
6 Apr 2010 6:54 PM
Last revision by
Maheshkumar S Tiwari
When:
18 Sep 2013 4:56 PM
Revisions:
5
Comments:
1
Options
Subscribe to Article (RSS)
Share this
Can You Improve This Article?
Positively!
Click Sign In to add the tip, solution, correction or comment that will help other users.
Report inappropriate content using
these instructions
.
Wiki
>
TechNet Articles
>
Getting Information about a Variable in VBScript
Getting Information about a Variable in VBScript
Article
History
Getting Information about a Variable in VBScript
Since VBScript uses
variants
, it can be useful to find out what type of information ended up in a variable. Here is a simple subroutine to call all the built-in functions that return information about a variable.
Sub GetVarInfo(varname)
Wscript.Echo ""
Wscript.Echo "VarType = " & VarType(varname)
Wscript.Echo "TypeName = " & TypeName(varname)
Wscript.Echo "IsArray = " & IsArray(varname)
Wscript.Echo "IsDate = " & IsDate(varname)
Wscript.Echo "IsEmpty = " & IsEmpty(varname)
Wscript.Echo "IsNull = " & IsNull(varname)
Wscript.Echo "IsNumeric = " & IsNumeric(varname)
Wscript.Echo "IsObject = " & IsObject(varname)
Wscript.Echo "Count = " & varname.count
Wscript.Echo ""
End Sub
Say you do the following in your script (you'll need to include the code above too if you actually wanted to run this on your own):
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
Set colOperatingSystem = objWMIService.ExecQuery("SELECT Caption FROM Win32_OperatingSystem")
GetVarInfo(strComputer)
GetVarInfo(objWMIService)
GetVarInfo(colProcesses)
Here is the resulting output from
GetVarInfo(strComputer)
:
VarType = 8
TypeName = String
IsArray = False
IsDate = False
IsEmpty = False
IsNull = False
IsNumeric = False
IsObject = False
That is as simple as it gets. It is a string that is not any of the following - array, date, empty, null, numeric, object or null.
Here is the
GetVarInfo(objWMIService)
output:
VarType = 9
TypeName = SWbemServicesEx
IsArray = False
IsDate = False
IsEmpty = False
IsNull = False
IsNumeric = False
IsObject = True
The
TypeName
function will return something different depending on the type of object it is. In this case it knows enough to tell me it is a
SWbemServicesEx
object. In other cases it might return
Object
for a generic object,
Unknown
for an unknown object, or
Nothing
for an object variable that does not yet refer to an object instance. Since Count is only valid for collections, that line generates an error but the script continues because On Error Resume Next is included at the beginning of the script.
Here is the output from
GetVarInfo(colProcesses)
:
VarType = 9
TypeName = SWbemObjectSet
IsArray = False
IsDate = False
IsEmpty = False
IsNull = False
IsNumeric = False
IsObject = True
Count = 71
A
SWbemObjectSet
is a collection of WMI objects. Since it is a collection, the count of items in the collection is displayed.
en-US
,
has code
,
script
[Edit tags]
Leave a Comment
Please add 8 and 6 and type the answer here:
Post
Wiki - Revision Comment List(Revision Comment)
Sort by:
Published Date
|
Most Recent
|
Most Useful
Comments
Maheshkumar S Tiwari
18 Sep 2013 4:56 PM
Maheshkumar S Tiwari edited Revision 3. Comment: Added tags
Edit
Page 1 of 1 (1 items)
Wikis - Comment List
Sort by:
Published Date
|
Most Recent
|
Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Posted by
Maheshkumar S Tiwari
on
18 Sep 2013 4:56 PM
Maheshkumar S Tiwari edited Revision 3. Comment: Added tags
Edit
Page 1 of 1 (1 items)