Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,

Slides:



Advertisements
Similar presentations
ISOM3230 Business Applications Programming
Advertisements

L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Tableau Lab 2 Calculations and Parameters. Data Set The fundraising data set uses a JOIN to combine two worksheets - Funds and Pledges - from one source.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Val Function A Function performs an action and returns a value The expression to operate upon, known as the argument, (or multiple arguments), must be.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Chapter 2 Data Types, Declarations, and Displays
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Data Types 1.
Fundamentals of Python: From First Programs Through Data Structures
Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
Dani Vainstein1 VBScript Session 1. Dani Vainstein2 Subjets for Session 1 Vbscript fundamentals. Variant subtypes. Variables. Option Explicit statement.
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Dani Vainstein1 VBScript Session 3. Dani Vainstein2 What We learn Last seasson? How to declare arrays. Working with one dimensional a multi- dimensional.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter Making Decisions 4. Relational Operators 4.1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
28 Formatted Output.
C Formatted Input/Output
VBScript Session 1 Dani Vainstein.
VBScript Session 3.
VBScript Session 1 IT Professional Academy.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Chapter 4 – Fundamental Data Types
2.5 Another Java Application: Adding Integers
The Selection Structure
Other Kinds of Arrays Chapter 11
Chapter 4: Making Decisions.
Chapter 4 – Decisions 4.1 Relational and Logical Operators
Chapter 6 Variables What is VBScript?
WEB PROGRAMMING JavaScript.
VBScript Session 6 Dani Vainstein.
Numbers.
VBScript Session 7 Dani Vainstein.
Do While (condition is true) … Loop
VBScript Session 1.
Chapter 2 Primitive Data Types and Operations
Chapter 2 Modular Programs with Calculations and Strings
Presentation transcript:

Dani Vainstein1 VBScript Session 9

Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables, objects and functions.

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

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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 NIS – 50% Between And NIS – 55% 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.

Make sure to visit us Tutorials Articles Proikects And much more 26