CIS16 Application Development and Programming using Visual Basic.net

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 6- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Advertisements

Chapter 6, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 6 Sub Procedures And Functions.
Lists, Loops, Validation, and More
Sub and Function Procedures
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Chapter 7: Sub and Function Procedures
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
1.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
VBA Modules, Functions, Variables, and Constants
Programming Based on Events
Chapter 7: Sub and Function Procedures
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Programming with Microsoft Visual Basic th Edition CHAPTER SEVEN SUB AND FUNCTION PROCEDURES.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Seven Sub and Function Procedures.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Chapter 6 Procedures and Functions Instructor: Bindra Shrestha University of Houston – Clear Lake CSCI
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Why to Create a Procedure
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Programming with Microsoft Visual Basic 2008 Fourth Edition
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Chapter 6 Sub Procedures
Chapter 9: Writing Procedures Visual Basic.NET Programming: From Problem Analysis to Program Design.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
1.
1 Week 5 More on the Selection Structure. 2 Nested, If/ElseIf/Else, and Case Selection Structures Lesson A Objectives After completing this lesson, you.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
Course ILT Using complex selection structures Unit objectives Include radio buttons and check boxes in an interface, create and call a user- defined Sub.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Visual Basic I Programming
Visual Basic Fundamental Concepts
Programming Right from the Start with Visual Basic .NET 1/e
UNIT 1 Lesson 1 Introduction.
Chapter 9 Programming Based on Events
A variable is a name for a value stored in memory.
INF230 Basics in C# Programming
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Computing with C# and the .NET Framework
IS 350 Application Structure
Chapter 8: Writing Graphical User Interfaces
Chapter 10: Void Functions
Using Procedures and Exception Handling
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Repeating Program Instructions
Visual Basic..
Chapter 6 Sub Procedures
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS16 Application Development Programming with Visual Basic
CIS16 Application Development and Programming using Visual Basic.net
The List Box Control Items can be placed into the list at design time or run time The Sorted property causes items in the list to be sorted automatically.
CIS 16 Application Development Programming with Visual Basic
Lecture Set 10 Windows Controls and Forms
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
CIS16 Application Development and Programming using Visual Basic.net
GUI Programming in Visual Studio .NET
Presentation transcript:

CIS16 Application Development and Programming using Visual Basic.net Chapter Six Sub and Function Procedures

Procedures There are two types of procedures in Visual Basic Sub Procedures perform actions but do not return a value to the calling code Function Procedures Perform actions and return a value to the calling code

Sub Procedures There are two types of Sub procedures Event Sub Procedures Procedures related to events, such as a button’s Click event or a text box’s TextChanged event Private Sub clearButton_Click(sender As Object, e as EventArgs) Handles clearButton.Click avgLabel.text = String.Empty gradeLabel.Text = String.Empty End Sub Independent Sub procedures Processed only when called (invoked) from code Invoked by using the Call statement

Independent Sub Procedures

Including Parameters (variables) in an Independent Sub Procedure A parameter is a memory location that stores an item of data passed to the procedure when the procedure is invoked Each parameter in the parameterList has procedure scope, which means it can be used only within the procedure The data is passed to the procedure through the Call statement’s argumentList, which is a comma-separated list of arguments you want passed to the procedure Call AddNumbers(intNum1, intNum2) Private Sub AddNumbers(x,y) ….. End Sub

Passing Variables passed as arguments, received as parameters Variables have both a value and a unique address for its location in the computer’s internal memory You pass either a copy of the variable’s value or its address to the receiving procedure Passing a copy of the variable’s value is referred to as passing by value Passing its address is referred to as passing by reference

Passing Variables by Value To pass a variable by value, you include the keyword ByVal The variable’s value is passed to the receiving procedure Original value cannot be changed in the procedures

Passing Variables by Reference To pass a variable by reference, you include the keyword ByRef The memory location of the variable is passed to the receiving procedure With ByRef, the original value can be changed in the procedures

Function Procedures A Function procedure returns a value after performing its assigned task Function procedures are referred to as functions The value is returned by the Return statement, which typically is the last statement within a function

Function Procedures (cont'd.)

Function Procedures (cont'd.)

Function Procedures example

Event Signatures Events have a signature comprised of the object raising the event (the sender) and the event being raised (e) Private Sub clearButton_Click(sender As Object, e as EventArgs) Handles clearButton.Click avgLabel.text = String.Empty gradeLabel.Text = String.Empty End Sub

Events with identical actions Can create a procedure that can be executed by more than one event handler - this avoids duplicating code The approach shown below, handles each unique event and each handler executes code in another procedure One procedure for all handlers Individual handlers

Events with identical actions (cont.) Can associate a procedure with more than one object and event - this avoids duplicating code

Desk Checking code Desk-checking is the process of reviewing the program instructions while seated at your desk rather than in front of the computer Also called hand-tracing because you use a pencil and paper to follow each of the instructions by hand

Math Class The math functions in VB.NET are defined in the System.Math class of the .NET Framework To use these functions without qualification, the System.Math namespace must be imported into the project by adding the namespace at the top of the source code: Imports System.Math ... Dim MyVar1 As Double = 2.8 Dim MyVar2 As Double MyVar2 = Round(MyVar1) ' Returns 3 To use these functions with qualification, do not use the imports statement, but instead coding dot notation, code the class name followed by the method name MyVar2 = Math.Round(MyVar1) ' Returns 3

Math Class

“Collection” Controls Collections – an ordered set of items that can be referred to as a unit Common methods are Add, Remove, Clear Common controls are Listbox & ComboBox https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.collection(v=vs.110).aspx

Including a Combo Box in an Interface Displays only one item initially and the user needs to click on the handle of the combo box to view the items in a drop-down Allows the user to select from a number of choices Allows the user to type an entry not on the list Can save space on a form

Including a Combo Box in an Interface (cont.) DropDownStyle property has three values: Simple DropDown (default) DropDownList

Populating a Combo Box – design time Building at design time add items to the list at design time, by typing values into the String Collections Editor You will have to type an item under the text property in order to display the default item at runtime.

Populating a Combo Box - runtime) Build at run time in form load event

Populating a Combo Box - user input You can also allow the user to add their own items using the InputBox function, as follows: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim myitem myitem = InputBox(“Enter your Item”) ComboBox1.Items.Add(myitem) End Sub

Removing items from a Combo Box at design time, simply open the String Collection Editor and delete the items at line by line or all at once using the Delete key. Remove method Private Sub Delete_Click(sender As Object, e As EventArgs) Handles Button2.Click ComboBox1.Items.Remove(“Visual Basic 6”) End Sub Clear method Private Sub Btn_Clr_Click(sender As Object, e As EventArgs) Handles Button2.Click ComboBox1.Items.Clear()

Programming a Combo Box (cont.)

Chapter application