Data Types and Variables Part D – Common Methods (ToString and Parse)

Slides:



Advertisements
Similar presentations
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Advertisements

Chapter 3.1 Controls Programming In Visual Basic.NET.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Chapter 4 Introduction to Numeric Data Types and Variables.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
C# Introduction ISYS 350. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
How to Work with Numeric and String Data
Formatting and Parsing. Slide 2 Introduction Two core topics Parsing - Converting strings to other types (numbers, dates, …) Formatting Converting those.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Graphical User Interfaces 2 Tonga Institute of Higher Education.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Controls. Adding Controls to Form -You can pick controls from the toolbox. -To add the controls from Toolbox to the Form You have be in design view. -To.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
C# Introduction ISYS 350. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 4 Designing the Inventory Application Introducing TextBox es and Button s.
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
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.
Lecture Set 6 The String and DateTime Data Types Part B – Characters and Strings String Properties and Methods.
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
C# Introduction ISYS 350.
IS 350 Numeric Data Types.
A variable is a name for a value stored in memory.
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
IS 350 Application Structure
Chapter 1: An Introduction to Visual Basic 2015
Value-Returning Functions
Chapter 2 – Introduction to the Visual Studio .NET IDE
Multiple Classes and Inheritance
Variables and Arithmetic Operations
C# Introduction ISYS 350.
ICS103 Programming in C Lecture 3: Introduction to C (2)
C# Introduction ISYS 350.
Chapter 3 Fundamentals of Programming in Visual Basic 3
Lecture Set 4 Data Types and Variables
C# Introduction ISYS 350.
Visual programming Chapter 3: GUI (Graphical User Interface) Part I
C# Introduction ISYS 350.
Variables and Arithmetic Operations
C# Introduction ISYS 350.
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
C# Introduction ISYS 350.
WEB PROGRAMMING JavaScript.
C# Introduction ISYS 350.
Part A – Doing Your Own Input Validation with Simple VB Tools
Chapter 3: Introduction to Problem Solving and Control Statements
Introduction to Tools, Numeric Data Types and Variables
C++ programming in Windows environment Text controls in the program
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Building an Application in the Visual Basic .NET Environment
CIS 16 Application Development Programming with Visual Basic
Lecture Set 11 Creating and Using Classes
C# Introduction ISYS 350.
Visual Studio.
Topics Designing a Program Input, Processing, and Output
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
Visual C# - GUI and controls - 1
Reading from and Writing to Files
JavaScript: Introduction to Scripting
Programming In Visual Basic.NET
C# Introduction ISYS 350.
Reading from and Writing to Files
Presentation transcript:

Data Types and Variables Part D – Common Methods (ToString and Parse) Lecture Set 4 Data Types and Variables Part D – Common Methods (ToString and Parse) Text Boxes, Input Focus

Objectives Learn about two Common Methods for converting To a formatted string (Tostring) from a primitive (or other) value From a string to a primitive value (Parse) Examine Imports Future Value Learn how to use the TextBox control Define the order in which control instances get input focus 11/10/2018 7:35 PM

Formatting Output Strings There are a number of common functions that can be used to convert and format data. These include the ToString method, which converts an argument to a string which can be specially formatted Also, a Parse method which converts a string to an equivalent data value Visual Studio supports named formats to supply common formatting -- currency, for example Data can be formatted with format specifiers Custom formats can be created with placeholder characters 11/10/2018 7:35 PM

The ToString and Parse Methods Both are conversion methods common to all data types defined by .NET So we can write … Decimal.Parse (“234.567D”); … DateTime.Parse (“Jan 30, 2007”); How does the compiler know which version of these functions to use? What would happen if we wrote … Decimal.Parse (“Jan 30, 2007”); 11/10/2018 7:35 PM

Formatting Data Using ToString Here we see another version of the ToString method Previously we had seen a version of ToString that took a primitive type value as an argument Now we have a version of the Common Method ToString that takes a format descriptor (or no argument) With the format descriptor, the specified value to converted to a formatted string A format specifier consists of a single alphabetic character followed by an optional numeric precision indicator  11/10/2018 7:35 PM

Format Descriptors Format descriptors may be Specifier strings consisting of a single alphabetic character followed by an optional numeric precision specifier A format string or mask consisting of special placeholder characters and literal characters value.ToString(“C”); value.ToString (“D6”); value.ToString(“$###,###.00”); Examples next …  11/10/2018 7:35 PM

Format Specifiers 11/10/2018 7:35 PM

Placeholder Characters 11/10/2018 7:35 PM

Format Strings (Examples) 11/10/2018 7:35 PM

The FV Function The FV function calculates the future value of an investment (like do we really have any?) The first argument contains the interest rate The second argument contains the number of periods The third argument contains the amount of the periodic payment The optional fourth argument contains the present (initial) value of the investment The optional fifth argument defines whether payments are made at the beginning or end of the period Slide 11 11/10/2018 7:35 PM

The FV Function (Example) 1 Calculate the future value of $1,000.00 for 12 periods at 1% per period double monthRate = 0.01; int monthTerm = 12; double initialValue = 1000.00; double futureValue; futureValue = FV(0.01, 12, 0, 1000); futureValue = FV (monthRate, monthTerm, 0, initialValue);

The FV Function (Example) 2 But the FV functions returns a negative value So what do we do? Using System.Convert; ‘Why? InitialValue = ToDouble(txtInitialValue.Text); AnnualInterestRate = … ; YearlyTerm = ToInt32(txtYearlyTerm.Text); MonthlyTerm = … FutureValue = FV(…) FutureValue = System.Math.Abs(FutureValue); // Convert to string in currency format and store in box // Note different ways to call operators such as toString lblFutureValue.Text = FutureValue.ToString(“C”); 11/10/2018 7:35 PM

The TextBox Control (Introduction) The TextBox control gets input and displays output The control derives from the TextBoxBase class Other textual controls include the MaskedTextBox and RichTextBox controls 11/10/2018 7:35 PM

The TextBox Control (Properties) 1 The BorderStyle property defines the style of the border The ForeColor and BackColor properties define text and background colors The Enabled property defines whether the control instance can get input focus The ReadOnly property controls whether the text in the control instance can be copied to the clipboard The MultiLine property defines whether text will appear on multiple lines The maximum number of characters is defined in the MaxLength property 11/10/2018 7:35 PM

The TextBox Control (Properties) 2 The ScrollBars property defines whether scroll bars appear Scroll bars only appear when the MultiLine property is True The Text property stores the visible text The TextAlign property defines how the text is aligned in the control instance The size and position is defined by the X, Y, Height, and Width properties 11/10/2018 7:35 PM

The TextBox Control (Methods and Events) The Focus method is used to set input focus to a text box The Enter event fires when the control instance gets focus The Leave event fires when the control instance loses focus 11/10/2018 7:35 PM

Introduction to Tab Order Every form has exactly one active control instance at run time This is the control instance having input focus The order in which control instances get focus is called the tab order The tab order is set using the TabIndex property The tab order can also be set using a visual designer 11/10/2018 7:35 PM

Setting the Tab Order 11/10/2018 7:35 PM

Other Issues (optional) Read about enumerations – nothing new here Nullable types – can be used to indicate that a variable has never been defined – in other words that the value is unknown Used only for value variables Int? myVariable = null; // null is a keyword You should never depend on a language system to initialize data for you. Do it yourself explicitly If you do this carefully you will probably not need to use nullable types NOTE: Reference variables are by default assigned the null value 11/10/2018 7:35 PM