📄 vbs6.htm
字号:
<HTML>
<HEAD>
<TITLE>VBScript Data Types</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="CATEGORY" CONTENT="Tutorial">
<META NAME="Description" CONTENT="VBScript Data Types">
</HEAD>
<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft® Visual Basic® Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>VBScript Data Types</B></FONT>
</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2> <A HREF="vbstutor.htm">VBScript Tutorial</A> <BR> <A HREF="vbs9.htm">Previous</A> | <A HREF="vbs15.htm">Next</A> <P></FONT>
</TD></TR>
</TABLE>
<BR>
<HR NOSHADE SIZE=1>
<H5>What Are VBScript Data Types?</H5>
<BLOCKQUOTE>
VBScript has only one data type called a <B>Variant</B>. A <B>Variant</B> is a special kind of data type that can contain different kinds of information, depending on how it's used. Because <B>Variant</B> is the only data type in VBScript, it's also the data type returned by all functions in VBScript.<P>
At its simplest, a <B>Variant</B> can contain either numeric or string information. A <B>Variant</B> behaves as a number when you use it in a numeric context and as a string when you use it in a string context. That is, if you're working with data that looks like numbers, VBScript assumes that it is numbers and does the thing that is most appropriate for numbers. Similarly, if you're working with data that can only be string data, VBScript treats it as string data. Of course, you can always make numbers behave as strings by enclosing them in quotation marks (" ").
</BLOCKQUOTE>
<H5>Variant Subtypes</H5>
<BLOCKQUOTE>
Beyond the simple numeric or string classifications, a <B>Variant</B> can make further distinctions about the specific nature of numeric information. For example, you can have numeric information that represents a date or a time. When used with other date or time data, the result is always expressed as a date or a time. Of course, you can also have a rich variety of numeric information ranging in size from Boolean values to huge floating-point numbers. These different categories of information that can be contained in a <B>Variant</B> are called subtypes. Most of the time, you can just put the kind of data you want in a <B>Variant</B>, and the <B>Variant</B> behaves in a way that is most appropriate for the data it contains.<P>
The following table shows the subtypes of data that a <B>Variant</B> can contain.<P>
<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR BGCOLOR=#DDDDDD VALIGN=TOP><TD WIDTH=15%><FONT SIZE=2><B>Subtype</B></FONT></TD><TD WIDTH=85%><FONT SIZE=2><B>Description</B></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Empty</B></FONT></TD>
<TD><FONT SIZE=2><B>Variant</B> is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Null</B></FONT></TD>
<TD><FONT SIZE=2><B>Variant</B> intentionally contains no valid data. </FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Boolean</B></FONT></TD>
<TD><FONT SIZE=2>Contains either <A HREF="vbs247.htm"><B>True</B></A> or <A HREF="vbs243.htm"><B>False</B></A>.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Byte</B></FONT></TD>
<TD><FONT SIZE=2>Contains integer in the range 0 to 255. </FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Integer</B></FONT></TD>
<TD><FONT SIZE=2>Contains integer in the range -32,768 to 32,767. </FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Currency</B></FONT></TD>
<TD><FONT SIZE=2>-922,337,203,685,477.5808 to 922,337,203,685,477.5807.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Long</B></FONT></TD>
<TD><FONT SIZE=2>Contains integer in the range -2,147,483,648 to 2,147,483,647.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Single</B></FONT></TD>
<TD><FONT SIZE=2>Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Double</B></FONT></TD>
<TD><FONT SIZE=2>Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Date (Time)</B></FONT></TD>
<TD><FONT SIZE=2>Contains a number that represents a date between January 1, 100 to December 31, 9999.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>String</B></FONT></TD>
<TD><FONT SIZE=2>Contains a variable-length string that can be up to approximately 2 billion characters in length.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Object</B></FONT></TD>
<TD><FONT SIZE=2>Contains an object.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><B>Error</B></FONT></TD>
<TD><FONT SIZE=2>Contains an error number.</FONT></TD></TR>
</TABLE>
You can use <A HREF="vbs238.htm">conversion functions</A> to convert data from one subtype to another. In addition, the <A HREF="vbs216.htm"><B>VarType</B></A> function returns information about how your data is stored within a <B>Variant</B>.
</BLOCKQUOTE>
<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">© 1997 by Microsoft Corporation. All rights reserved.</a></em></p>
</FONT>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -