Practical Programming COMP153-08A Lecture 4:Strings & Formatting.

Slides:



Advertisements
Similar presentations
Ch. 3 Variables VB.Net Programming. Data Types Boolean – True or False values Short – Small integers (+/- 32,767) Integer – Medium-size integers (+/-
Advertisements

Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Practical Programming COMP153-08S Lecture: Repetition Continued.
Practical Programming COMP153-08S Lecture 6: Making Decisions Part II.
Lesson 4: Formatting Input Data for Arithmetic
1.
Introduction to Computers and Programming Lecture 7:
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Data Types 1.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Chapter 4 Introduction to Numeric Data Types and Variables.
Chapter 3: Using Variables and Constants
CS0004: Introduction to Programming Input and Output.
CS0004: Introduction to Programming Variables – Strings.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Lecture 8 Visual Basic (2).
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.
Type Conversions Implicit Conversion Explicit Conversion.
Computer Science: A Structured Programming Approach Using C1 2-7 Input/Output Although our programs have implicitly shown how to print messages, we have.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
CS 0004 –Lecture 3 Jan 10, 2011 Roxana Gheorghiu.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Practical Programming COMP153-06S Lecture 3: Making Decisions.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
1 STRINGS String data type Basic operations on strings String functions String procedures.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
مقدمة في البرمجة Lecture 7. Write VB.net project using the for loop to calculate : 1- the sum of numbers from 1 to (A) numbers. 2- the sum of Odd numbers.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
Input, Output and Variables GCSE Computer Science – Python.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
7 - Programming 7J, K, L, M, N, O – Handling Data.
IS 350 Numeric Data Types.
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Review Materials I (T) Subject : T0016 – ALGORITHM AND PROGRAMMING
Introduction to the C Language
Data Types and Conversions, Input from the Keyboard
Data Types, Arithmetic Operations
Variables and Arithmetic Operations
Chapter 3: Using Variables and Constants
C# Introduction ISYS 350.
Other Kinds of Arrays Chapter 11
Lecture Set 4 Data Types and Variables
Variables and Arithmetic Operations
Lecture 13 Input/Output Files.
البرمجة بلغة فيجول بيسك ستوديو
Variables, operators, canvas, and multimedia
C# Introduction ISYS 350.
CIS16 Application Development Programming with Visual Basic
Sub Procedures and Functions
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER FOUR VARIABLES AND CONSTANTS
VB Variables and Data
Lecture 5 SQL FUNCTIONS.
Understanding Variables
CS 1054 Introduction to Programming in Java
Presentation transcript:

Practical Programming COMP153-08A Lecture 4:Strings & Formatting

Tools -> Options

Programming So Far First: Controls, Properties, Events Second: Types and Arithmetic Third: Variables and some Input/Output Today: –Strings & Formatting

Consider this code Dim x As Integer x = Val(TextBox1.Text) TextBox2.Text = Str(x) Use x = and x = 12.51

Formatting Input To be more “precise” we use: Convert: –Dim x As Integer –x = Convert.ToInt32(TextBox1.Text) –We can ToDouble, ToInt16 (short), ToSingle, ToDouble.

Example Dim x, y As Integer x = Convert.ToInt32(TextBox1.Text) y = Convert.ToInt32(TextBox2.Text) Label1.Text = Str(x) & Str(y) Label2.Text = Str(x) + Str(y) Label3.Text = x.ToString + y.ToString Label4.Text = x.ToString & y.ToString

Example in action

Formatting output Numeric –Generally: VARNAME.ToString(formatString) Examples – currency format (“c”) Dim price As Single price = Val(TextBox1.Text) Label1.Text = price.ToString("C")

Price Example

Decimal Places Change the “C” to “N2” (for two decimal places) Dim price As Single price = Val(TextBox1.Text) Label1.Text = price.ToString(“N2")

Percentage Change to “P” Dim price As Single price = Val(TextBox1.Text) Label1.Text = price.ToString(“P")

Strings Strings have many associated methods –Dim s As String = “I am a string” –MessageBox.Show(s.Length) Strings and spacing –Dim s As String = “123” –Label1.Text = s –Label2.Text = s.PadLeft(5) –Label3.Text = s.PadLeft(10) –Can also use PadRight

Padding to total length

Bigger Example

Solution Dim x, y As Integer x = Val(TextBox1.Text) y = Val(TextBox2.Text) Label1.Text = "Mod of " & x & " " & y & " = " & x Mod y Label2.Text = "Exp of " & x & " " & y & " = " & x ^ y Label3.Text = "Div of " & x & " " & y & " = " & x \ y Label4.Text = "Concat of " & x & " " & y & " = " & Str(x) + Str(y)

Test on Friday 9-11 in Lab 3 9 questions (40 marks) Topics –Computer components (4) –Controls (2) –Setting properties (4) –Setting properties 2 (4) –Events (6) –Arithmetic 1 (4) –Types (4) –Arithmetic 2 (10) –Formatting (2)

THE END of the lecture