Input/Output CE 311 K - Introduction to Computer Methods Daene C. McKinney.

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

Introduction to C Programming
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Chapter 1 - An Introduction to Computers and Problem Solving
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:
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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 8 - VB.Net by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files Creating a Sequential File Adding Items to a Sequential File Error Trapping.
Module 1.4 File management. Contents Introduction Windows Explorer The need to organise More about files Working with files Test and improve your knowledge.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 31 Fundamentals of Programming in Visual Basic (Continue VI) String Properties and Methods: "Visual".Length is 6. "Visual".ToUpper is VISUAL. "123.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
Saving and Loading Simple Text Files A sequential file stores characters one after the other like songs on a cassette tape. New characters are added to.
Computer and Programming File I/O File Input/Output Author: Chaiporn Jaikaeo, Jittat Fakcharoenphol Edited by Supaporn Erjongmanee Lecture 13.
1 Chapter 1 - An Introduction to Computers and Problem Solving 1.1 An Introduction to Computers 1.2 Windows, Folders, and Files 1.3 Program Development.
Introduction to Access By Mary Ann Chaney and Alicia Harkleroad.
CS0004: Introduction to Programming Input and Output.
Intrinsic Functions Pre-coded Functions Used to improve developer productivity Broad Range of Activities Math calculations Time/Date functions String.
File Handling. Data Files Programs that can only get data from the user interface are limited. –data must be entered each time. –only small amounts of.
1 Chapter 8 – Text Files 8.1 Managing Text Files 8.2 StreamReaders, StreamWriters, and Structured Exception Handling 8.3 XML.
1 Text Files Managing Text Files StreamReaders, StreamWriters, ReadAllLines, and WriteAllLines Method The OpenFileDialog Control Structured Exception Handling.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET VB.NET Controls VB.NET Events Numbers Strings Input and Output.
Chapter 8 - VB 2008 by Schneider1 Chapter 8 – Sequential Files 8.1 Sequential Files 8.2 Using Sequential Files.
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.
Creating Sequential Files, Adding Data, & Deleting Data.
Subprograms CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introduction to Programming with RAPTOR
Tutorial 9: Sequential Access Files and Printing1 Tutorial 9 Sequential Access Files and Printing.
Numbers continued The Integer Data Type Multiple Declarations Parentheses Three Types of Errors.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
BACS 287 File-Based Programming. BACS 287 Data Hierarchy  Database - Collection of files, relationships, integrity information, etc  Files - All records.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
XP New Perspectives on Microsoft Windows XP Tutorial 2 1 Microsoft Windows XP Working with Files Tutorial 2.
Introduction to Programming Python Lab 5: Strings and Output 05 February PythonLab5 lecture slides.ppt Ping Brennan
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 3 - VB 2008 by Schneider1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
Chapter 6 Controlling Program Flow with Looping Structures.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Introduction to Programming
Chapter 6 JavaScript: Introduction to Scripting
Chapter 3 – Variables, Input, and Output
Project 9 Creating Pop-up Windows, Adding Scrolling Messages, and Validating Forms.
Files.
Ch 10 Sequential Access Files
© 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.
Chapter 8 – Sequential Files
WEB PROGRAMMING JavaScript.
Fundamentals of Programming in VB.NET
Section 3.3 Numbers Arithmetic Operations Variables
Variable Review & IO User 12/26/2018.
Chapter 3.5 Input and Output
Input and Output.
Additional Topics in VB.NET
CIS16 Application Development and Programming using Visual Basic.net
Topics Introduction to File Input and Output
BO65: PROGRAMMING WRITING TO TEXT FILES.
Input and Output.
Input and Output Chapter 3.5
Presentation transcript:

Input/Output CE 311 K - Introduction to Computer Methods Daene C. McKinney

Introduction Formatting Numbers Input From Files Output To Files Input Boxes

Formatting Numbers Display numbers in familiar formats Examples: FormatNumber( , 1)  12,345.6 FormatCurrency( , 2)  $12, FormatPercent(0.185, 2)  18.5% Display “n” rounded to “r” decimal places and display with commas Display dollar sign then “n” to “r” decimal places and display with commas Display “n” as a percent rounded to to “r” decimal places and percent sign

How Do I Use That? Go Button Stop Button ListBox1 Button1 Button2

Input From Files Three ways: – Assign values to variables in program – Read values from a file – Enter values in text box

Files and Folders File: holds programs or data. Its name usually consists of letters, digits, and spaces. Filenames: – Up to 156 characters (letters, digits, etc.) – Extension (.txt,.doc, etc) Pathnames: – Where does a file live? – Path to the folder containing a file: C:\temp\ 6

Key Terms: Folders and Files Term Example Disk Hard disk, flash drive, DVD File name Payroll Extension.txt Filename Payroll.txt Path TextFiles\Payroll.txt Filespec C:\TextFiles\Payroll.txt 7

8 CSV File Format Comma Separated Values (CSV) Records are stored on one line with a comma between each field Example: USStates.txt Delaware,DE,1954, Pennsylvania,PA,44817, New Jersey,NJ,7417, Georgia,GA,57906, (name of state, abbreviation, area, population)

Sample CSV File First two lines of USStates.txt Delaware,DE,1954, Pennsylvania,PA,44817, name abbreviation area population 9

Example w/o Files This is painful!

Open & Read Files Data stored in a text file can be read one line at a time with a StreamReader object. Declare a variable that can read from files: Dim sr As IO.StreamReader = IO.File.OpenText(filespec) – filespec is the file to be read – A pointer is set to the first line of the file. Read data from the file str = sr.ReadLine – Reads the line pointed to, assigns the line to the string variable str, and moves the pointer to the next line of the file. – The value of str.EndOfStream will be True after the entire file has been read. – The statement str.Close() terminates communication with the file.

Split Operator The Split operator provides a way to recover the values from a CSV file. text = line.Split(”,”c) This “splits” the string variable “line” into pieces. The splits are made where a comma appears. The pieces are assigned to the text variable “text()”. text(0) will have the text preceding the 1 st comma, text(1) will have the text between the 1 st and 2 nd commas, etc.

Sample CSV File First line of USStates.txt line = “Delaware,DE,1954,759000” text = line.Split(“,”c) text(0) text(1) text(2) text(3) 13 DelawareDE

Example w/Files This is painful!

15 Getting Input from an Input Dialog Box stringVar = InputBox(prompt, title) fullName = InputBox("Enter your full name.", "Name") title prompt

Example w/Files This is painful!

The OpenFileDialog Control Implements File Open dialog box Found in Dialogs group of Toolbox Icon will appear below Document window. 17

18 Using the OpenFileDialog Control To display the control: OpenFileDialog1.ShowDialog() After the Open button has been pressed, the file name selected and its complete filespec will be contained in the property: OpenFileDialog1.FileName

Example w/Files That’s better! File to open

20 Using a Message Dialog Box for Output MessageBox.Show(prompt, title) MessageBox.Show("Nice try, but no cigar.", "Consolation") title prompt

Open & Write a File Data can be placed in a text file one line at a time with a StreamWriter object. Dim sw As IO.StreamWriter = IO.File.CreateText(filespec) – filespec is the file to be created and written – Establishes link between computer and disk drive for writing Write data to the file sw.WriteLine(info) – initally places the information (info) into the first line of the file – Subsequent statements of that form place information into lines at the end of the file The statement sw.Close() terminates communication with the file.

Write to a File Open input file Open output file Write to output file Read from input file Dim sw As IO.StreamWriter

Write to a File Open input file Open output file Write to output file Read from input file

Using Text Boxes for I/O The content of a text box is always a string We can use the contents of a text box to assign values to variables We can use the contents of a variable to assign values to text boxes Numbers typed into text boxes are stored as strings and should be converted to numbers before using in calculations

Example

Summary Formatting Numbers Input From Files Output To Files Input Boxes