CS0004: Introduction to Programming Input and Output.

Slides:



Advertisements
Similar presentations
CS0004: Introduction to Programming Select Case Statements and Selection Input.
Advertisements

Chapter 3: Using Variables and Constants
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Input Dialog Box An input dialog box can be used to obtain a single item of input from the user Presents a window (dialog box) requesting input Syntax:
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
On to… string operations & functions. Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Chapter 5 new The Do…Loop Statement
Chapter 31 Fundamentals of Programming in Visual Basic (Continue VI) String Properties and Methods: "Visual".Length is 6. "Visual".ToUpper is VISUAL. "123.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
Intrinsic Functions Pre-coded Functions Used to improve developer productivity Broad Range of Activities Math calculations Time/Date functions String.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Chapter 3 Part 21 Displaying Output Chapter 3 Section 3.5Output Formatting Chapter 3 Section 3.6Group Boxes, etc. Chapter 3 Section 3.7Sample Program Chapter.
CS0004: Introduction to Programming Variables – Strings.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Review for Mid-term! October 26, Review Homework Worksheet True or False Operators are symbols that perform specific operations in Visual Basic.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
Numbers continued The Integer Data Type Multiple Declarations Parentheses Three Types of Errors.
Chapter 8 - Visual Basic Schneider
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
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.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Chapter 4 Getting Started with VBA. Subroutines Subroutine is the logical section of code that performs a particular task. Subroutine is also called a.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 3: Chapter 3: Slide 1 Unit 3 Formatting Chapter 3 Input, Variables, Constants,
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
1 VB-06-String Manipulation Mar 03, 2002 String Function VISUAL BASIC.
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.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Chapter 6 Controlling Program Flow with Looping Structures.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
A variable is a name for a value stored in memory.
Variables and Arithmetic Operations
Chapter 3: Using Variables and Constants
Variables and Arithmetic Operations
WEB PROGRAMMING JavaScript.
Chapter 3 – Variables, Input, and Output
String Variable, Methods and Properties
Section 3.3 Numbers Arithmetic Operations Variables
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
String Variable, Methods and Properties
String Variable, Methods and Properties
String Variable, Methods and Properties
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Presentation transcript:

CS0004: Introduction to Programming Input and Output

Review  A String is…  a sequence of characters that is treated as a single item  A String literal is surround by…  double quotes ( “” )  Typecasting is…  converting from one type to another  Explicit Typecasting Functions  CDbl(parameter) – typecasts to double  CInt(parameter) – typecasts to integer  CStr(parameter) – typecasts to string  Concatenation is…  combining multiple strings into one string  The concatenation operator is… &&

Review  Two options that should be turned on in every program you write…  Option Strict On  Option Explicit On  Some string methods and properties are…  Length  ToUpper  ToLower  Trim  Substring  IndexOf

Formatting Numbers  VB provides functions for formatting numbers to familiar forms.  Note: These all return strings  Specify the number of decimal places FormatNumber(n,r) Example: FormatNumber( , 3) returns 1,  Return in currency form FormatCurrency(n,r) Example: FormatCurrency( , 2) returns $1,  Return in a percent form FormatPercent(n,r) Example: FormatPercent(0.3452, 2) returns 34.53%

Masked Text Box  You can avoid doing data validation in some cases by forcing the user to input data in a specific form using a masked text box.  Demo  Create control  Click on the triangle on the control  Select “Set Mask”  Custom Masks  See course webpage

Date Data Type  Visual Basic also provides a date data type Dim theDate As Date  Date literals are surrounded by pound signs (#) Dim theDate As Date = #2/7/2011#  You can convert dates into strings of different formats much like the number data types FormatDateTime(theDate, DateFormat.LongDate)  See the course webpage for different date formats  Some date functions  Today  Returns today’s date  DateDiff(DateInterval.Day, date1, date2)  Returns the number of days between date1 and date2 as an integer.  See course webpage for different date intervals  theDate.AddYears(n), theDate.AddMonths(n), and theDate.AddDays(n)  Returns the date after adding n years, months, and days (respectively) to theDate.  CDate(dateString)  Typecasts the string dataString to a date data type

Date Example  New Topics:  Date date type  Date literals  Masked text box  CDate typecasting  Today function  FormatDateTime function  DateDiff function  AddDays function

Input Dialog Box  Sometimes we want to get a piece of information once and do not want to waste screen space with a text box and a label. For this we use an input dialog box. InputBox(prompt, title)  prompt is the message displayed inside of the dialog box  title is the text displayed in the title of the dialog box  This function returns the string that is in the text box in the dialog box when the user presses OK.  Thus, you want to store the result returned into a variable Dim userInput As String userInput = InputBox(“Please Enter Input”, “Input”)

Output Dialog Box  You can also display a dialog box that takes no input, but just displays a message. This is called an output dialog box. MessageBox.Show(prompt, title)  prompt and title are the same as in the input dialog box.  This displays a dialog with the message and an OK button.

Dialog Boxes Examples  New Topics  Variable scope  OnLoad event procedure  Input dialog box  Output dialog box

Named Constants  Sometimes you want to define a variable that will keep the same value throughout the running of the program. These are called constants. Const CONSTANT_NAME As Type = value  Notes:  Const makes the constant not able to take a different value after initialization  The name of the constant should be all in caps and have underscores instead of camel case for different words  You need to initialize the constant for it to have a value