CSI 101 Elements of Computing Spring 2009 Lecture #13 Programming in Visual Basic March 25 th – April 4 th, 2009.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Objectives After completing this lesson, you should be able to do the following: Describe various types of conversion functions that are available in.
Copyright © 2007, Oracle. All rights reserved Using Single-Row Functions to Customize Output Modified: October 21, 2014.
The Binary Numbering Systems
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
1 ICS103 Programming in C Lecture 4: Data Types, Operators & Expressions.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
CSI 101 Elements of Computing Spring 2009 Lecture #6: Data Types and Variables in Visual Basic Wednesday, Februrary 11th, 2009.
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
CSI 101 Spring 2009 Review and Recap of Visual Basic Wednesday, April 29 th.
Basic Elements of C++ Chapter 2.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Strings PART II STRING$ AND SPACE$. Create strings of specified number String$ creates string of specified character Space$ creates string of spaces Example:
Dani Vainstein1 VBScript Session 9. Dani Vainstein2 What we learn last session? VBScript coding conventions. Code convention usage for constants, variables,
Topics Built-in functions commonly used in business applications String functions and formatting Dates and Times Formatting Data for output Error handling.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
IT253: Computer Organization
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
Using Decimal Types. What are the data types that you can use? Decimal Number: Single -Is used for decimal values that will not exceed six or seven digits.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Conversion Functions.
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Object-Oriented Application Development Using VB.NET 1 Chapter 4 VB.NET Programming with Supplied Classes.
Microsoft Access Prepared by the Academic Faculty Members of IT.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
CHAPTER FOUR Performing Calculations and Manipulating Data: Expressions.
Chapter 6: Using VB.NET Supplied Classes Visual Basic.NET Programming: From Problem Analysis to Program Design.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
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,
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Bill Tucker Austin Community College COSC 1315
Creating Database Objects
A variable is a name for a value stored in memory.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Lesson 18 Math Functions Lesson 19 Format Functions
The Selection Structure
IDENTIFIERS CSC 111.
CIS16 Application Development and Programming using Visual Basic.net
CSI 101 Elements of Computing Spring 2009
Data Types & File Size Calculations
Introduction to Primitive Data types
Coding Concepts (Data- Types)
VBScript Session 10.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Data Types and Expressions
Unit 3: Variables in Java
Internal Functions.
Creating Database Objects
Introduction to Primitive Data types
Presentation transcript:

CSI 101 Elements of Computing Spring 2009 Lecture #13 Programming in Visual Basic March 25 th – April 4 th, 2009

Development Steps Determine algorithm Know what you're doing before you start Define data What do I get from the user? What do I give to the user? Decide needed functions What is already available in the language? What do I need to create? Design Forms What should the user see? Don't put too much on one Form Make it easy to read 2

Defining Data List input and output Determine best data type For instance, a Name would be a String Look for opportunities to create composite types These are the user-defined types you saw earlier, like Ualb_Student or Employee Why? Easier to catalog and associate Fewer “loose” variables running around Figure out source of information Files, databases, or user input 3

Library Functions These are functions that come with the compiler Supposed to make life easier for developers, as they don't have to “reinvent the wheel” Main categories: Mathematical Type conversion String manipulation File manipulation (which we've already seen) Formating Date manipulation There are others, but we won't discuss them in this course 4

Type conversion functions Probably most important, since all data in text boxes on Form are String Need to convert to appropriate variable to perform calculations and arithmetic operations All have form Ctype, where type is the data type desired CByte, CInt, CLng – convert to Byte, Integer, Long CDec, CSng, CDbl – convert to Decimal, Single, Double CBool – converts 0, 1, “True”, “False”, “Yes”, “No” CDate – converts from valid date format string 5

Conversion Examples CDate(“01/01/09”) CDate(“September 11, 2001”) CBool(1) CBool(“True”) CBool(“no”) CInt(Text1.Text) 6

Mathematical Functions All trig functions Log() and exp() These we might use: Abs() - returns absolute value Sqrt() - returns Decimal with square root 7

String Manipulation Functions Len(String) : returns number of characters in string Left(String, Int) : returns substring of first Int characters of String Right(String, Int) : returns substring of last Int characters of String LCase(String) : returns String in all lowercase UCase(String) : returns String in all upper case Mid(String,Pos,Len) : returns substring starting at Pos with Len characters 9

String Manipulation Functions, cont Mid(String, Pos) : returns substring starting at Pos containing the rest of String Example: Mid(“ABCDEFG”, 3) returns “CDEFG” StrComp(String1, String2) Returns 0 if both strings are the same Returns 1 if String2 would be alphabetically sorted before String1 Returns -1 if String1 would be alphabetically sorted before String2 LTrim(String) : returns String without leading blanks 10

Last String Manipulation Functions RTrim(String) : returns String without trailing blanks Trim(String) : returns String without extra blanks at either end StrReverse(String) : returns String in reverse order InStr(String1, String2) : returns integer start position of String2 in String1 Returns 0 if not there InStr(“ABCDEF”,”B”) returns 2 11

Format function Format(Value, form) : returns Value formatted in the specified form Form can be a string or a predefined format String ex: Format(454, “#,##0.00”) Format(ThisDate, “mm/dd/yyyy”) Predefined ex: Format(ThisDate, “Long Date”) Format(454, “Currency”) Note value can be a String, Date, or numerical value or variable Form is always a String 12

Numerical Predefined Formats “General” or “G” : displays without thousand separator “Currency” or “C” : displays dollar sign, separator, and two decimal places “Fixed” or “F” : displays at least one digit to the left of decimal and two digits after decimal “Standard” or “S” : displays thousand separator and two decimal digits “Percent” : Multiplies number by 100 and displays with percent sign immediately following “P” : Multiplies number by 100 and displays with percent sign behind number, with a space in between “Scientific” : Displays in scientific notation with two decimal digits “E” : Displays in scientific notation with up to six decimal digits 13

Special Numerical Formats “D” : display numerical value as a string with two decimal digits “X” : display numerical value as a hexadecimal value Displays in Base 16 with an X following In Base 16, are displayed as A-F “True/False” : displays False if value = 0, otherwise True “Yes/No” : displays No if value = 0, otherwise Yes “On/Off” : displays Off if value = 0, otherwise On 14

Numerical Format symbols “0” : display that digit location, even if value is 0 Format(45,”000”) displays 045 “#” : displays digit if there, nothing if not Format(45, “##0”) displays 45 “.” : decimal placeholder. What follows is number of decimal digits to display Format(45,”0.00”) displays “,” : thousand separator. If value > 1000, puts comma after thousand digit “%” : multiplies value by 100 and displays percent sign afterwards 15

Predefined Date/Time formats “General Date” or “G” : Displays in standard m(m)/d(d)/yyyy format with time following 10/29/2008 6:50:00 PM “Long Date” or “D” : displays whole date Wednesday, October 29, 2008 “Short Date” or “d” : displays standard date 10/29/2008 “M” : display just month and day October 29 “Y” : display just month and year October,

Date/Time Format symbols “d” : displays day without leading zero “dd” : displays two digits for day “ddd” : displays day as abbreviated text Ex: “Wed” “dddd” : displays full name for day Month has same format, but with M Format(Today,”MMM dd”) displays Oct 29 Format(Today, “MM/dd”) displays 10/29 Year has same format, but with y Format(Today,”M/d/yy”) displays 10/29/08 17

Special Format functions FormatCurrency(value) : returns string with value in currency format FormatPercent(value) : returns string with value in percent format FormatDateTime(value, DateFormat) : returns string with value in specified date format: DateFormat.GeneralDate DateFormat.LongDate DateFormat.ShortDate 18

Date Manipulation Functions Now() : returns current day Today = Now() Month(date) : returns integer value for month Month(Today) returns 10 MonthName(date,abbr) : returns string name of month Abbr is a Boolean which says whether to return abbreviated name MonthName(Today,True) returns Oct Day(date) : returns integer value of day Year(date) : returns integer value of year 19

More Date Manipulation Functions Weekday(date) : returns integer value of day of week (Sunday is 1) Weekday(Today) returns 4 WeekdayName(date,abbr) : returns string name of day of week Abbr is Boolean – should I abbreviate? WeekdayName(Today) returns Wed 20

Date Arithmetic Functions DateAdd(interval, amount, date) : Adds amount of interval to date and returns new date Intervals: “d” for day “w” for weekday “m” for month “q” for quarter (three months) “yyyy” for year DateAdd(“m”, 1, Today) returns Nov 29, 2008 DateDiff(interval, date1, date2) : returns integral number of intervals between date1 and date2 DateDiff(“d”,Yesterday,Today) is 1 DateDiff(“d”,Today,Yesterday) is -1 21

Time Functions There are functions dealing with time, but we won’t cover them in this course See the Visual Basic Reference on 22

Let’s Practice The rest of this lecture is a demonstration of creating the Form and code for the following problem statement: “Obtain a name from the user. Search for that name in file Employee. When found, display the employee’s date of hire, current Manager, and current salary.” 23

Steps Get requirements Determine algorithm Define data Map Form Write code Test

Get requirements Initial problem statement seems fine Check source file to determine additional questions

Employee file Each record has these fields: First Name Last Name Manager’s Name Office number Office phone number Date of hire Salary

Questions to user Since Employee name is split, do you want to search on either first name or last name? Answer: “Yes” Does the user need to specify the exact name, or will a “fuzzy” search do? Answer: “fuzzy search”

Okay, let’s get to work… The rest is done on Notepad, in Visual Studio, or on whiteboard. Slides showing Notepad and whiteboard work will be added to the end of this lecture after the Practice is complete.