Download presentation
Presentation is loading. Please wait.
Published byPatricia Webster Modified over 9 years ago
1
Dani Vainstein1 VBScript Session 9
2
Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables, objects and functions.
3
Dani Vainstein3 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
4
Dani Vainstein4 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.
5
Dani Vainstein5 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. For example, Chr(10) returns a linefeed
6
Dani Vainstein6 Conversion Functions Data Type Conversions - CBool Returns an expression that has been converted to a Variant of subtype Boolean. If expression is zero, False is returned; otherwise, True is returned. If expression can't be interpreted as a numeric value, a run- time error occurs.
7
Dani Vainstein7 Conversion Functions Data Type Conversions - CByte Returns an expression that has been converted to a Variant of subtype Byte. 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 CByte to force byte arithmetic in cases where currency, single- precision, 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.
8
Dani Vainstein8 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 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.
9
Dani Vainstein9 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 day- of-the-week string.
10
Dani Vainstein10 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 single- precision 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.
11
Dani Vainstein11 Conversion Functions Data Type Conversions - CInt Returns an expression that has been converted to a Variant of subtype 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 double- precision arithmetic normally would occur. Use the CInt function to provide internationally aware conversions from any other data type to an Integer subtype. If expression lies outside the acceptable range for the Integer subtype, an error occurs.
12
Dani Vainstein12 Conversion Functions Data Type Conversions - CLng Returns an expression that has been converted to a Variant of subtype Long. For example, use CInt or CLng to force integer arithmetic in cases where currency, single-precision, or double- precision 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 lies outside the acceptable range for the Long subtype, an error occurs.
13
Dani Vainstein13 Conversion Functions Data Type Conversions - CSng Returns an expression that has been converted to a Variant of subtype 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 lies outside the acceptable range for the Long subtype, an error occurs.
14
Dani Vainstein14 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.
15
Dani Vainstein15 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 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.
16
Dani Vainstein16 Conversion Functions Base Conversions - Hex Returns a string representing the hexadecimal value of a 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. You can represent hexadecimal numbers directly by preceding numbers in the proper range with &H. For example, &H10 represents decimal 16 in hexadecimal notation.
17
Dani Vainstein17 Conversion Functions Base Conversions - Oct Returns a string representing the octal value of a 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. 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.
18
Dani Vainstein18 Variables Subtypes Verification Because wrong usage of data can cause run-time errors, VB provides a set of critical data varification functions. IsArray - IsArray(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. IsArray is especially useful with variants containing arrays.
19
Dani Vainstein19 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. 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.
20
Dani Vainstein20 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 is always returned if expression contains more than one variable.
21
Dani Vainstein21 Variables Subtypes Verification IsNull Function Returns a Boolean value that indicates whether an expression contains no valid 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 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 <> Null, are always False. This is because any expression containing a Null is itself Null, and therefore, False.
22
Dani Vainstein22 Variables Subtypes Verification IsNumeric Function Returns a Boolean value indicating whether an expression can be evaluated as a number. The expression argument can be any expression. IsNumeric returns True if the entire expression is recognized as a number; otherwise, it returns False. IsNumeric returns False if expression is a date expression.
23
Dani Vainstein23 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 user- defined object; otherwise, it returns False.
24
Dani Vainstein24 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.
25
Dani Vainstein25 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. Check if input size is > 0 before enter sub.
26
Make sure to visit us Tutorials Articles Proikects And much more www.AdvancedQTP.com 26
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.