Vb Script

Share Embed Donate


Short Description

vb script...

Description

VBSCRIPT VARIABLES AND DATATYPES

What Is a Variable? A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during execution

Declaring Variables We declare variables explicitly in our script using the Dim Dim statement,  statement, the Public statement, and the Private Private statement.  statement. We declare multiple variables by separating each variable name with a comma. For example: Dim Top Top,, ottom, !eft, "ight We can also declare a variable implicitly by simply using its name in our script. ecause we may misspell the variable name in one or more places, causing unexpected results During execution. For that reason, the Option Explicit statement Explicit  statement is available to re#uire explicit declaration of all variables. The $ption %xplicit statement should be the first statement in the script. Option explicit:

When We use the $ption %xplicit statement, you must explicitly declare all variables using the Dim, &rivate, &ublic, or "eDim statements. 'f we attempt to use an undeclared variable name, causing an error occurs. (aming "estrictions )ariable )ariable names follow the standard rules for naming anything in )*cript. A variable name: •

+ust begin with an alphabetic character.



annot contain an embedded e mbedded period.



+ust not exceed - characters.



+ust be uni#ue in the scope in which it is declared.

Assigning )alues to )ariables

)alues are assigned to variables creating an expression as follows: the variable is on the left side of the expression and the value you want to assign to the variable is on the right. For example:  / -00

DATATYPES What Are VBScript Data Types?

VBScript has nly ne !ata type calle! a Variant" A Variant is a special #in! $ !ata type that can cntain !i$$erent #in!s $ in$r%atin& !epen!ing n h' it(s )se!. ecause )ariant is the only data type in )*cript, it1s also the data type returned by all functions in )*cript. At its simplest, a )ariant can contain either numeric or string information. A )ariant 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 you1re wor2ing with data that loo2s li2e numbers, )*cript assumes that it is numbers and does the thing that is most appropriate for numbers. *imilarly, if you1re wor2ing with data that can only be string data, )*cript treats it as string data. $f cou rse, you can always ma2e numbers behave as strings by enclosing them in #uotation mar2s 34 45. Variant S)btypes The $ll'ing table sh's the s)btypes $ !ata that a Variant can cntain"

*ubtype

Description

E%pty

Variant is )ninitiali*e!" Val)e is + $r n)%eric ,ariables r a *er-length string .//0 $r string ,ariables"

N)ll

Variant intentinally cntains n ,ali! !ata"

Blean

Cntains either Tr)e r 1alse"

Byte

Cntains integer in the range + t 233"

Integer

Cntains integer in the range -42&567 t 42&565"

C)rrenc y

-822&445&2+4&673&955"37+7 t 822&445&2+4&673&955"37+5"

Lng

Cntains integer in the range -2&:95&974&697 t 2&:95&974&695"

Single

Cntains a single-precisin& $lating-pint n)%ber in the range -4"9+2724E47 t -:"9+:287E-93 $r negati,e ,al)es; :"9+:287E-93 t 4"9+2724E47 $r

psiti,e ,al)es" D)ble

Cntains a !)ble-precisin& $lating-pint n)%ber in the range -:"585684:4976242E4+7 t -9"89+6369379:295E-429 $r negati,e ,al)es; 9"89+6369379:295E-429 t :"585684:4976242E4+7 $r psiti,e ,al)es"

Date .Ti%e0

Cntains a n)%ber that represents a !ate bet'een bect

Cntains an bect"

Errr

Cntains an errr n)%ber"

Operator Precedence When se,eral peratins cc)r in an e=pressin& each part is e,al)ate! an! resl,e! in a pre!eter%ine! r!er calle! peratr prece!ence . 6ou can use parentheses to override the order of precedence and force some parts of an expression to be evaluated before others. $perations within parentheses are always performed before those outside. Within parentheses, however, standard operator precedence is maintained. When e=pressins cntain peratrs $r% %re than ne categry& arith%etic peratrs are e,al)ate! $irst& c%parisn peratrs are e,al)ate! ne=t& an! lgical peratrs are e,al)ate! last" C%parisn peratrs all ha,e e@)al prece!ence; that is& they are e,al)ate! in the le$tt-right r!er in 'hich they appear" Arith%etic an! lgical peratrs ar e e,al)ate! in the $ll'ing r!er $ prece!ence"

Arithmetic Description

Symbol

Exponentiation

^

Unary negation

-

Multiplication

*

Division

/

Integer division

\

Modulus arithmetic

Mod

Addition

+

Subtraction

-

String concatenation

&

omparison

Description

Symbol

E!uality

"

Ine!uality

#$

%ess than

#

reater than

$

%ess than or e!ual to

#"

reater than or e!ual to

$"

'b(ect e!uivalence

Is

%ogical Description

Logical negation

Symbol

 Not

Logical conjunction

And

Logical disjunction

Or 

Logical exclusion

Xor 

Logical equivalence

Eqv

Logical imlication

!m

When multiplication and division occur together in an expression, each operation is evaluated as it occurs from left to right. !i2ewise, when addition and subtraction

occur together in an expression, each operation is evaluated in order of appearance from left to right. The string concatenation 375 operator is not an arithmetic operator, but in precedence it falls after all arithmetic operators and before all comparison operators. The 's operator is an ob8ect reference comparison operator. 't does not compare ob8ects or their values9 it chec2s only to determine if two ob8ect references refer to the same ob8ect. The lgic $ >R is that i$ at least ne $ the inp)ts are Tr)e& the )tp)t is tr)e; Tr)e >R Tr)e  Tr)e Tr)e >R 1alse  Tr)e 1alse >R Tr)e  Tr)e 1alse >R 1alse  1alse

>R nly ret)rns Tr)e i$ ne an! nly ne $ the inp)ts is Tr)e" Tr)e r Tr)e  1alse Tr)e r 1alse  Tr)e 1alse r Tr)e  Tr)e 1alse r 1alse  1alse

I%p ret)rns $alse i$ $irst ne is tr)e an! secn! ne $alse e=cept this it ret)rns tr)e"

Tr)e i%p Tr)e  Tr)e Tr)e i%p 1alse  1alse 1alse i%p Tr)e  Tr)e 1alse i%p 1alse  Tr)e

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF