CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.

Slides:



Advertisements
Similar presentations
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Slide 1 VB Programming Fundamentals. Slide 2 Visual Basic Language v VB language is powerful and easy to use v Descendent of BASIC (Beginner's All-Purpose.
Chapter 3 Variables, Constants, and Calculations
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
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.
IMS1906 Programming in VB.NET Week 3 – Lecture 1 Application Development © Angela Carbone Monash University School of Information Management.
CIS 234: Order of Operations, Shortcut & Other Operators Dr. Ralph D. Westfall February, 2004.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Spreadsheets Objective 6.02
Objectives You should be able to describe: Data Types
Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
2440: 211 Interactive Web Programming Expressions & Operators.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
1 Week 1: Variables, assignment, expressions READING: 1.2 – 1.4.
Chapter 3 Variables, Constants and Calculations Programming In Visual Basic.NET.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 2 Variables.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
INTRODUCTION TO DATABASE USING MICROSOFT ACCESS 2013 Part 5.1 November 16, 2014.
MICROSFTACCESS tables. DATA TYPES Field TypeWhat It Holds Short Text Text up to 255 characters long (including spaces and punctuation). Use a Text field,
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
Variables, Expressions, and IO
Numbers.
Chapter 2 Variables.
CSI 101 Elements of Computing Spring 2009
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Spreadsheets 2 Explain advanced spreadsheet concepts and functions
VB Variables and Data
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Spreadsheets Objective 6.02
EECE.2160 ECE Application Programming
Unit 3: Variables in Java
Spreadsheets Objective 6.02
Chapter 2 Variables.
EECE.2160 ECE Application Programming
Chapter 2 Modular Programs with Calculations and Strings
Presentation transcript:

CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011

Things Can Do in Statements nAge = 57 (assign value) sValue = CStr( ) (VB function) dPrice = ListPrice(dCost) (user function) [Call] PrintData(sStates()) (procedure) frmInput.Text = "Inputs" (set property) If nAge > 17 Then … (test value[s])

Assignment Statements nCount = 0 sState(1) = "AK" dTotal = dTotal + dItemCost or dTotal += dItemCost 'above is extremely common code pattern sFullName = "Abraham " & "Lincoln" 'concatenation sMonth = CStr(Month(Now)) ' function

Math: Operator Precedence highest to lowest level (PEMDAS) 1. ( ) parentheses 2. ^exponentiation (raise to a power) 3. –negation (reverse the sign) 4. *, / multiply, divide 5. \integer division (no decimals) 6. modmodulus arithmetic (remainder) 7. +, –add, subtract calculate left to right if on same level

Integer Division and Modulus \ (backslash) gives integer part of result of dividing 2 integers e.g., 7\4 = 1 doesn't work with decimal numbers if Option Strict On, decimal numbers are rounded to integers if Option Strict Off Mod gives remainder after integer division e.g., 7 Mod 4 = 3

ASCII Codes (decimal values) 0 – 31 = printer control commands 32 – 47, 58 – 64, 91 – 96 are all punctuation marks 32=space, 33=!, 34=", 35=#, 36=$, etc. 48 – 57 = 0 – 9 65 – 90 = A – Z 97 – 122 = a – z Wikipedia articleWikipedia article (reasons for choices)

Working with ASCII Codes sChar = Chr(65) [sChar value is "A"] returns letter of code number in parentheses nChar = Asc("a") [nChar value is 97] returns ASCII code number of letter in parentheses vbCrLf = carriage return & line feed ASCII characters 13 and 10 together shows text on separate lines e.g., MsgBox

Formatting Outputs general formatting function [string].Format(argument,[format]) defaults: Start>Control Panel> Regional and Language (try on own computer) argument is value or variable to format use format style name, or format string TextBox1.Text = _'line continuation Format(CStr(1.0/7.0), "Fixed") TextBox2.Text=Format(3/0.7,"#.000")

Named Number Format Styles General Number – as is e.g., Currency – symbol, commas, 2 decimals e.g., $1, (rounds: 2 decimals) Fixed – 1+ digit left of decimal, 2 on right e.g., 0.91, (rounds: 2 places) Standard – like fixed, but with commas e.g., 1, (also rounds) 'notes

Number Format Styles - 2 Percent – shown as 12.3% Scientific - for very big or very small #s 6.78E12 = 6,780,000,000,000 ' *10^ E-12 = ' *10^-12 Yes/No: No = 0, all other #s = Yes True/False: like Yes/No, 0 = False On/Off: like Yes/No, 0 = Off

Format Strings for Numbers 0 – shows the digit, or 0 if it is zero # – shows digits > 0, and spaces for leading and trailing zeros (e.g.,  10.2). (decimal), (comma)'insert punctuation % – shows %, multiplies decimals by 100 format strings enclosed in quotes Format(fCost, "0.00") other examples: "#,###.####" "#.0%"

Format Strings for Numbers - 2 can use 1-3 argument strings to format numeric data (separated by semicolons) 1 string: for all values ' "$#,##0" 2 strings: 1 st is for positives & zeros, 2 nd is for negatives ' "$#,##0;($#,##0)" 3 strings: 1 st is for positives, 2 nd negatives, 3 rd zeros ' "$#,##0;($#,##0);--" skip string: uses previous ' "$#,##0;;--"

Named Date/Time Format Styles enclose date data with pound signs #yyyy-mm-dd hh:mm:ss# Format(#3/15/2010#, "General Date") General Date – date, time 10/10/01 11:46:04 PM 'VS changes to 2001 Long Date or Medium Date – Wednesday, October 13, 2010 Short Date – 10/11/2010

Named Time Format Styles Format(#6:30:00 AM#, "Long Time") Long Time or Medium Time – 11:53:38 PM Short Time – 11:53 PM Military Time? used to be available, but I couldn't find a predefined format for this

Format Strings for Dates Format(datNow, "mm/dd/yy") month:m 7 mm 07 mmm Jul day: d 3 dd 03 ddd Wed year: yy 05 yyyy 2005 / slash separator other strings for dates, and also for time formatting

FormatCurrency Function defaults from Control Panel Regional and Language OptionsControl Panel Regional and Language Options numeric formatsformats FormatCurrency(Expression 'numeric [,NumDigitsAfterDecimal [,IncludeLeadingDigit * [,UseParensForNegativeNumbers * [,GroupDigits *]]]]) '*TriState.True [False, UseDefault]

Formatting Functions defaults [English (United States)] FormatCurrency$12, FormatNumber–12, ' – for negative #s FormatPercent % 'times 100 FormatDateTimemm/dd/yyyy hh:mm:ss Round 'default = whole # if don't specify decimals

Working with Dates Now – gives current time/date Month(Now), Day(Now), or Year(Now) gives current month, day or year number Format(Now, "w") day of week (Sun = 1) 1 st day of week is different in some countries e.g., Monday in France Dim datShop as Date = DateDiff("d", Now, CDate("12/25/2011"))) datAddHalfMon = DateAdd("w", 2, Now) w = # of weekdays, ww= # of weeks, m=# of months, y=# of years in formula