B VBScript09

Share Embed Donate


Short Description

Download B VBScript09...

Description

VBScript Session 9

What we learn last session?

VBScript coding conventions. Code convention usage for constants, variables, objects and functions.

Subjects for session 9 Conversion functions. OS Conversions Asc, Char

Data Types conversions CBool, CByte, CCur, CDate, CDbl, Char, CInt, Clng, CSng, CStr

Base Conversions Hex, Oct

Variables subtypes verification. IsArray, IsDate, IsEmpty, IsNull, Is Numeric, IsObject

Conversion Functions OS Conversions - Asc Returns the ANSI character code corresponding to the first letter in a string. The string argument is any valid string expression. If the string contains no characters, a run-time error occurs.

Conversions Functions - Char  Returns the character associated with the specified ANSI character code. The charcode argument is a number that identifies a character. Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. Chr( (10) returns a linefeed For example, Chr

Conversion Functions Data Type Conversions - CBool Returns an expression that has been converted to a Variant of subtype Boolean Boolean.. If expression If expression is zero, False is returned; otherwise, True is returned. If expression If expression can't be interpreted as a numeric value, a runtime error occurs.

Conversion Functions Data Type Conversions - CByte Returns an expression that has been converted to a Variant of subtype Byte Byte.. In general, you can document your code using the subtype conversion functions functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CByte to force byte arithmetic in cases where currency, singleprecision, double-precision, or integer arithmetic normally would occur. Use the CByte function to provide internationally aware conversions from any other data type to a Byte subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators.

Conversion Functions Data Type Conversions - CCur  Returns an expression that has been converted to a Variant of  subtype Currency In general, you can document your code using the subtype conversion functions to show that the result of some operation should be expressed as a particular data d ata type rather than the default data type. For example, use CCur to force currency arithmetic in cases where integer arithmetic normally would occur. You should use the CCur function to provide internationally aware conversions from any other data type to a Currency subtype.

Conversion Functions Data Type Conversions - CDate Returns an expression that has been converted to a Variant of subtype Date. Use the IsDate function to determine if  date can be converted to a date or time. CDate recognizes date literals and time literals as well as some numbers that fall within the range of acceptable dates.

When converting a number to a date, the whole number portion is converted to a date. CDate recognizes date formats according to the locale setting of your system.

The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings. In addition, a long date format is not recognized if it also contains the dayof-the-week string.

Conversion Functions Data Type Conversions - CDate Returns an expression that has been converted to a Variant of subtype Double. In general, you can document your code using the subtype conversion functions to show that the result of some operation should be expressed as a particular data type rather than the default data type. For example, use CDbl or CSng to force double-precision or singleprecision arithmetic in cases where currency or integer arithmetic normally would occur. Use the CDbl function to provide internationally aware conversions from any other data type to a Double subtype. For example, different decimal separators and thousands separators are properly recognized depending on the locale setting of your system.

Conversion Functions Data Type Conversions - CInt Returns an expression that has been converted to a Variant of subtype Integer Integer.. In general, you can document your code using the subtype conversion functions to show that the result of  some operation should be expressed as a particular data type rather than the default data type. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or doubleprecision arithmetic normally would occur. Use the CInt function to provide internationally aware conversions from any other data type to an Integer subtype. If expression If expression lies outside the acceptable range for the Integer subtype, an error occurs.

Conversion Functions Data Type Conversions - CLng Returns an expression that has been converted to a Variant of subtype Long Long.. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or doubleprecision arithmetic normally would occur. Use the CLng function to provide internationally aware conversions from any other data type to a Long subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators. If expression If expression lies outside the acceptable range for the Long subtype, an error occurs.

Conversion Functions Data Type Conversions - CSng Returns an expression that has been converted to a Variant of subtype Single Single.. For example, use CDbl or CSng to force double-precision or single-precision arithmetic in cases where currency or integer arithmetic normally would occur. Use the CSng function to provide internationally aware conversions from any other data type to a Single subtype. For example, different decimal separators are properly recognized depending on the locale setting of your system, as are different thousand separators. If expression If expression lies outside the acceptable range for the Long subtype, an error occurs.

Conversion Functions Data Type Conversions - CStr  Returns an expression that has been converted to a Variant of subtype String. Use the CStr function to provide internationally aware conversions from any other data type to a String subtype. You should use the CStr function instead of  Str to provide internationally aware conversions from any other data type to a String subtype.

Conversion Functions Data Type Conversions - CStr  The data in expression determines what is returned according to the following If expression is Boolean then CStr returns a string False.. containing True or False If expression is Date then CStr returns a string containing a date in the short-date format of your system. If expression is Null then CStr returns a run-time error. If expression is Empty then CStr returns a zero-length String (""). If expression is Error then CStr returns a string containing the word Error followed by the error number. If expression is Other Numeric then CStr returns a string containing the number.

Conversion Functions Base Conversions - Hex Returns a string representing the hexadecimal value of a number. If number  If number  is not already a whole number, it is rounded to the nearest whole number before being evaluated. If number  is Null then Hex returns Null. If number  is Empty then Hex returns Zero(0). If number  is any other number then Hex returns Up to 8 hexadecimal characters. characters .

You can represent hexadecimal numbers directly by preceding numbers in the proper range with &H. For example, &H10 represents decimal 16 in i n hexadecimal notation.

Conversion Functions Base Conversions - Oct Returns a string representing the octal value of a number. If number  If number  is not already a whole number, it is rounded to the nearest whole number before being evaluated. If number  is Null then Oct returns Null. If number  is Empty then Oct returns Zero(0). If number  is any other number then Oct returns Up to 11 octal characters. characters .

You can represent octal numbers directly by preceding numbers in the proper range with &O. For example, &O10 is the octal notation for decimal 8.

Variables Subtypes Verification Because wrong usage of data can cause run-time errors, VB provides a set of critical data varification functions. IsArray - IsArray IsArray((varname) varname) Returns a Boolean value indicating whether a variable is an array. The varname argument can be any variable. IsArray returns True if the variable is an array; otherwise, it returns False False.. IsArray is especially useful with variants containing arrays.

Variables Subtypes Verification IsDate Function Returns a Boolean value indicating whether an expression can be converted to a date. The expression argument can be any date expression or string expression recognizable as a date or time. IsDate returns True if the expression is a date or can be converted to a valid date; otherwise, it returns False False.. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D. Ranges vary among operating systems.

Variables Subtypes Verification IsEmpty Function Returns a Boolean value indicating whether a variable has been initialized. However, because IsEmpty is used to determine if  individual variables are initialized, the expression argument is most often a single variable name. IsEmpty returns True if the variable is uninitialized, or is explicitly set to Empty; otherwise, it returns False False.. False is always returned if expression if expression contains more than one variable.

Variables Subtypes Verification IsNull Function Returns a Boolean value that indicates whether an expression contains no valid vali d data (Null). IsNull returns True if expression is Null, that is, it contains no valid data; otherwise, IsNull returns False.

If expression consists of more than one variable, Null in any constituent variable causes True to be returned for the entire expression. The Null value indicates that the variable contains no valid val id data. Null is not the same as Empty, which indicates that a variable has not yet been initialized.

It is also not the same as a zero-length string (""), which is sometimes referred to as a null string. Caution Use the IsNull function to determine whether an expression contains a Null value.

Expressions that you might expect to evaluate to True under some circumstances, such as If Var = Null and If Var Nul Null, l, are always False. This is because any expression containing a Null is itself Null, and therefore, False.

Variables Subtypes Verification IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number. n umber. The expression argument can be any expression. IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False False.. IsNumeric returns False if expression if expression is a date expression.

Variables Subtypes Verification IsObject Function

Returns a Boolean value indicating whether an expression references a valid Automation object. IsObject returns True if expression is a variable of Object subtype or a userdefined object; otherwise, it returns False.

Lab 9.1 In a company we have 3 divisions : “HR”,”R&D” and “QA” Each employee in each division, will asked by his name and Salary (Input box) title of input boxes the division name. The program will loop in a fixed for…next statement (for divisions). Employees will be entered in another loop, # of employees in each division = unknown. The default salary is 2800 NIS. Verify if the entered value for salary is a number, otherwise display a warning message + warning icon, and downgrade to zero. Use only two arrays.

Lab 9.1 Write a Sub procedure that outputs to the reporter the percenatge of taxes paid by each employee according to the follow tax table Until 2800 NIS  – 0% Between 2801 And 3500 NIS  – 10% Between 3501 And 4500 NIS  – 20% Between 4501 And 6500 NIS  – 30% Between 6501 And 9500 NIS  – 40% Between 9501 And 12000 NIS  – 50% Between 12001 And 15000 NIS  – 55% 15001 and above  – 60%

The calculation Itself will be calculated in the function GetTax(curSal). Tips : Use the Erase statement to reuse the arrays. Convert to subtype currency.

Make sure to visit us Tutorials Articles Proikects And much more www.AdvancedQTP.com

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF