VBScript learning notes-scope, explicit variable Declaration

Source: Internet
Author: User

<P> when a variable is declared or created in the script body, the global scope is used by default, the default value is private scope. </P>
<P> to explicitly declare the scope of a variable, public and private statements can be used. </P>
<Div class = "cnblogs_code" style = "border-top: # cccccc 1px solid; border-Right: # cccccc 1px solid; border-bottom: # cccccc 1px solid; padding-bottom: 5px; padding-top: 5px; padding-left: 5px; border-left: # cccccc 1px solid; padding-Right: 5px; Background-color: # f5f5f5 "> <PRE> <span style =" color: # 0000ff "> Public </span> myarray (<span style =" color: #800080 "> 10 </span>) </PRE> </div>
<P> & nbsp; </P>
<P> & nbsp; </P>
<P> by default, variables can be used without prior declaration. However, this may cause a spelling error and a new variable to be created, causing a bug. </P>
<P> Option explicit statements can help prevent such bugs. </P>
<P> use the option explicit statement as the first line of the script file, and then use the dim statement to list each variable used in the script. (<Em> Dim is often used to declare arrays, but can also be used to declare variables </em>) </P>
<Div class = "cnblogs_code" style = "border-top: # cccccc 1px solid; border-Right: # cccccc 1px solid; border-bottom: # cccccc 1px solid; padding-bottom: 5px; padding-top: 5px; padding-left: 5px; border-left: # cccccc 1px solid; padding-Right: 5px; Background-color: # f5f5f5 "> <PRE> <span style =" color: # 0000ff "> Option </span> <span style =" color: # 0000ff "> explicit </span>
<Span style = "color: # 0000ff"> dim </span> <span style = "color: #000000"> tomorrow
Tomorrow </span> = <span style = "color: #800000"> "</span> <span style =" color: #800000 "> Saturday </span> <span style =" color: #800000 ">" </span> <span style = "color: #000000">
Wscript. echo </span> <span style = "color: #800000"> "</span> <span style =" color: #800000 "> tomorrow is </span> <span style =" color: #800000 ">" </span> & amp; tomottow </PRE> </div>

<P> an error message is generated when the script runs to an undefined tomottow. If the option explicit statement is not available, no error is reported, but "Tomorrow is" is output directly. </P>

VBScript learning notes-scope, explicit variable Declaration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.