VB Built-in Functions School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 5, Monday 2/10/03)

Slides:



Advertisements
Similar presentations
Visual Basic Statements Chapter 5. Relational Operators  OperationSymbol  Equal  =  Less than  <  Greater than  >  Not equal   Less than.
Advertisements

Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
VB Numbers and Strings School of Business Eastern Illinois University (Week 4, Monday 2/03/2003) © Abdou Illia, Spring 2003.
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:
Fundamentals of Programming in Visual Basic
There is a String type in VB Data TypePrefix Stringstr Dim strFirstName As String strFirstName = “Homer” strFirstName = “” String A String variable can.
Built-In Functions.
Comparing Numeric Values If Val(Text1.Text) = MaxPrice Then (Is the current numeric value stored in the Text property of Text1 equal to the value stored.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Introduction to Computing Dr. Nadeem A Khan. Lecture 14.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
Fundamentals of Programming in Visual Basic
On to… string operations & functions. Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate.
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
Chapter 5 new The Do…Loop Statement
BACS 287 Visual Basic String Manipulation. BACS 287 Visual Basic Strings In Visual Basic, a “string” is a series of text, numbers, and special characters.
Programming Practice in Visual Basic The Initial Visual Basic Screen Toolbox Project Explorer window Properties window Form Menu bar Description pane.
Fundamentals of Programming in Visual Basic
Database Management Review for Final (Part 1) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Wednesday 4/30/2003)
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
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.
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
Manipulation Masterclass By the VB Gods. In this masterclass, we will learn how to use some of the string manipulation function such as Len, Right, Left,
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
1 E0001 Computers in Engineering Built in Functions.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Chapter 8 - Visual Basic Schneider
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
‘Tirgul’ # 2 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #2.
Sequential files School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 12, Monday 4/07/2003)
Variable, Constants and Calculations Dr Mohammad Nabil Almunawar.
Introduction to Programming Fundamentals of Programming in Visual Basic.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
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.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
© 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.
HNDIT Rapid Application Development
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
1 VB-06-String Manipulation Mar 03, 2002 String Function VISUAL BASIC.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
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.
© 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.
13/06/ Strings Left, Right and Trim. 213/06/2016 Learning Objectives Explain what the Left, Right and Trim functions do.
© 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. 
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
Chapter 3 - Visual Basic Schneider. Private Sub cmdEvaluate_Click() Dim n As Single, root As Single n = 6.76 root = Sqr(n) picResults.Print root; Int(n);
A variable is a name for a value stored in memory.
Fundamentals of Programming in Visual Basic
4.1 Strings ASCII & Processing Strings with the Functions
Input and Output.
Sub Procedures and Functions
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
Prepared By: Deborah Becker
VBScript Session 10.
Input and Output.
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Input and Output Chapter 3.5
Presentation transcript:

VB Built-in Functions School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 5, Monday 2/10/03)

2 Function ? n A sub program designed to: – perform a specific task, and – return a single value to the calling program. n Example: MonthlyDeposit = Val (txtDeposit.Text) The Val function will: - transform the string data entered by a user in numeric, and - return the numeric value to be assigned to MonthlyDeposit

3 Types of Functions n Built-In functions (part of VB library) – Example: Val n User-defined functions – Created by the user – Can be called by a program n Numeric Functions (manipulate numbers) n String Functions (manipulate strings)

4 Numeric Functions

5 n Examples Sqr (9) is 3Int(2.7) is 2Round(2.7) is 3 Sqr (0) is 0Int(3) is 3Round(2.317,2) is 2.32 Sqr (2) is Int(-2.7) is -3Round(2.317,1) is 2.3 Private Sub cmdEvaluate_Click() Dim n As Single, RootSquare As Single picResults.Cls n = 6.76 RootSquare = Sqr(n) picResults.Print RootSquare; Int(n); Round(n, 1) End Sub

6 String Functions Left ("String", n) Returns the number of specified characters, starting at the beginning of the string. Right ("String", n) Returns the number of specified characters from the end of the string. Mid ("String", m, n) Returns the character string starting at the position indicated by the first number and continuing for the length specified by the second number UCase ("String") Converts any lowercase letters in string to uppercase LCase ("String") Converts any uppercase letters in string to lowercase Val ("String") Returns the numbers contained in "String" as a numeric value Len ("String") Returns the number of characters in the string. Trim ("String ") Returns "String" with leading and trailing spaces removed.

7 String Functions n Examples Left ("fanatic", 3) is "fan"Right ("fanatic", 3) is "tic" Mid ("fanatic",5,1) is "t" UCase("Disk") is "DISK"LCase("Disk") is "disk" Trim("-12 ") is "-12"

8 Format Function n The format functions provide detailed control of how numbers, dates, and strings are displayed. n Example: FormatNumber ( , 1) 12,345.7 FormatCurrency ( , 2) $12, FormatPercent (.185, 2) 18.50% FormatDateTime(" ", vbLongDate) Wednesday, September 15, 1999

9 Exercises n 1. Given the data in the string variable y shown below, which of the following statements will assign the value ALL to the string variable x? y = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS" (A)x = Mid(y, 6, 3) (B)x = Left(y, 3) (C)x = Middle(y, 6, 3) (D)x = Right(y, 8)

10 Exercises n 2. What will be displayed in picBox when the following statements are executed? Dim a As String, b As String, c As String a = "THE WHOLE" b = "PART" c = Mid(a, Sqr(4), Len(b)) picBox.Print c (A)THE WHOLE PART (B)6 (C)HE W (D)HOLE (E)None of the above

11 Exercises n 3. What will be the output of the following statement? picBox.Print FormatCurrency( ) (A)$ (B)1, (C)$ (D)$1,234.57

12 Exercises n 4. What will be the output of the following statement? picBox.Print FormatNumber( , 3) (A) (B)1230 (C) (D)1,230

13 Exercises n 5. What will be the output of the following statement? picBox.Print FormatDateTime("1-2-99", vbLongDate) (A)Saturday, January 2, 1999 (B)January 2, 1999 (C)10/02/1999 (D)01/02/99 = 0

14 Exercises n 6. What will be the output of the following lines? Dim alphabet As String, soup As String alphabet = "abcdefghijklmnopqrstuvwxyz" soup = UCase(alphabet) picBox.Print Left(alphabet, 5); Left(soup, 5) (A)abcdeABCDE (B)ABCDEABCDE (C)eE (D)EE

15 Exercises n 7. What output is generated by the following statements (show the output EXACTLY as it would appear)? (A)picBox.Print Sqr(3^2 + 4^2) (B)picBox.Print Mid("Milkshake", 5, 5) (C)picBox.Print UCase("123jump")

16 Exercises n 8. Suppose a text box (named txtPhone) contains a (complete) phone number entered in the form xxx- xxx-xxxx. Write code to display the area code in a picOutput.

17 Exercises n 9. Write a program to generate a rent receipt. The program should request the person’s name, amount received, and the current date in text boxes and print a receipt of the type shown below on the printer. Received from Jane Smith the sum of $ Signed _____________________ Monday, October 1, 2002 cmdPrintReceipt txtDate txtName txtAmount