Visual Basic 6 Programming.

Slides:



Advertisements
Similar presentations
Sub and Function Procedures
Advertisements

CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
Lec6 P 1 CP2030 Visual Basic For C++ programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 6 Back To Index v Procedures and Parameters.
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
VB – Core III Functions Sub-routines Parameter passing Modules Scope Lifetime.
Function.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
1 Subroutines and Functions Chapter 6 in Deitel, Deitel and Nieto.
Visual Basic I Programming
Why to Create a Procedure
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look UTPA – Fall 2011.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
E0001 Computers in Engineering Procedures: subprograms and functions.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
Arrays1 From time to time an object (a variable, a picture, a label or a command) does not serve as well as a set of objects of a similar kind addressed.
Sub Procedures. A Sub procedure is a block of code that is executed in response to an event. There are two types of Sub procedures, general procedures.
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
CSCI 3327 Visual Basic Chapter 6: More Examples of Methods UTPA – Fall 2011.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?
6b – Sub Procedure With Parameters Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
BACS 287 Programming Fundamentals 5. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Procedures Built-in Functions User-defined.
Understanding Visual Basic Fundamentals CHAPTER 13 Understanding Visual Basic Fundamentals.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
Mark Dixon 1 Soft051 Examination Sample Questions.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Subroutines and Functions Chapter 6. Introduction So far, all of the code you have written has been inside a single procedure. –Fine for small programs,
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
1 By Dr. HANY ELSALAMONY. 1. What are differences between interpreted and compiled languages? 2. What are the programming steps to creating the Visual.
CS0004: Introduction to Programming
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Multiple Forms and Menus
Visual Basic Fundamental Concepts
Programming Right from the Start with Visual Basic .NET 1/e
IS 350 Application Structure
Examples of Classes & Objects
Visual Basic Variables
Functions and Procedures
Command Line Arguments
Method.
Working with Forms in Visual Basic
2. Understanding VB Variables
CSI 101 Elements of Computing – Spring 2009
Object-Oriented Programming: Classes and Objects
Visual Basic 6 Programming.
Chapter 4 - Visual Basic Schneider
Visual Basic..
Visual Basic 6 Programming.
Department Array in Visual Basic
1.الدوال Function 2.الاجراءاتSub Procedure 3.وحده نمطيه Add Module
Classes & Objects: Examples
Lbound and Ubound Functions
Visual Basic 6 Programming.
Procedures and Functions
Introduction to Visual Programming
Visual Basic 6 Programming.
CS285 Introduction - Visual Basic
Chapter 7: Using Functions, Subs, and Modules
Lecture 4 : January 2001 Dr. Andrew Paul Myers
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
The structure of programming
For...Next Statements.
Presentation transcript:

Visual Basic 6 Programming. Lecture 4 : February 2004 Dr. Andrew Paul Myers 29/12/2018

Functions. Functions return a value. So far you have been using inbuilt VB functions, e.g. sngValue = Sin(sngX_in_rads) dblPi = 4# * Atn(1#) VB allows you to write your own! i.e. dblRad = Radians(dblDegrees) 29/12/2018

Writing Functions. General Form: Private Function <name>( <parameters> ) As <type> <statement(s)> <name> = <return value> End Function Note : Functions can be Public, i.e. across all forms!! 29/12/2018

Example Function 1. Private Function Pi() As Double ‘ A parameterless function to return Pi. Pi = 4# * Atn(1#) End Function ************************ ‘ Use of this function. dlbPi = Pi() 29/12/2018

Example Function 2. Public Function Radians(dlbDegrees As Double) _ As Double ‘ Function to convert Degrees to Radians. Dim dblPi As Double ‘ A local variable. dlbPi=Pi() ‘ Call Pi function. Radians = dblPi * dblDegrees / 180# End Function 29/12/2018

Use of Function 2. Dim dlbValue As Double dblValue = Radians(90#) dblValue = Sin(Radians(90#)) 29/12/2018

Example Function 3. Public Function Add(intX As Integer, intY As _ Integer) As Integer ‘ Function to add two numbers together. Add = intX + intY End Function 29/12/2018

Use of Function 3. Dim intResult As Integer Dim intFirst As Integer, intSecond As Integer intResult = Add(1, 2) ‘ Not an array!!! intResult = Add(intFirst, intSecond) 29/12/2018

Arrays as Parameters. Private Function Sum(intValues() As Integer) As Integer Dim intLoop As Integer, intTotal As Integer ‘ local scope intTotal = 0 For intLoop = LBound(intValues) To UBound(intValues) intTotal = intTotal + intValues(intLoop) Next intLoop Sum = intTotal End Function 29/12/2018

Subroutines or Procedures. Functions return a value. Best suited to calculations. Subroutines/procedures do not, but they can modify the parameters (arguments) passed if required. Hence “returning” more than one value. The “Building Blocks” of a program! 29/12/2018

Subroutines. General Form: To execute: Public Sub <name>( <parameters> ) <statement(s)> End Sub To execute: Call <name>( <parameters> ) 29/12/2018

Writing Subroutines. Public Sub change_text(strText As String) strText = “It’s been changed!” End Sub To call: Call change_text(strSome_Text) Again Subs can be Public or Private. 29/12/2018

Multiple Forms. Projects can contain more than one Form. Use the “Add Form” option under the “Project” pull down menu. Addressing Object/Control Properties: <Form>.<Object>.<Property> = <Value> 29/12/2018

Displaying Multiple Forms. <Form Name>.Show <Form Name>.Hide To speed up Form display times use the Load command in the subroutine Form_Load() on the first Form. e.g. Private Sub Form_Load() Load Form2 Load Form3 End Sub 29/12/2018

Using Multiple Forms. e.g. Form2.TextBox3.Text = “Hello” dblValue = Form2.Pi() * 180# Form2.Show Form2.Hide 29/12/2018

Exiting a Multiple Form Program. Private Sub Form_QueryUnload(Cancel _ As Integer, UnloadMode As Integer) Dim AForm As Form For Each AForm In Forms Unload AForm Next End End Sub 29/12/2018