Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
Advertisements

PROGRAMMING IN VISUAL BASIC PART 1
Tutorial 8: Developing an Excel Application
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
Microsoft Excel 2003 Illustrated Complete with Excel Programming.
Input Validation Check the values entered into a text box before beginning any calculations Validation is a form of ‘self-protection’, rejecting bad data.
Chapter 7: Sub and Function Procedures
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Creating Embedded Formative Assessment Dr. Steve Broskoske Misericordia University EDU 533 Computer-based Education.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
InvEasy (Project1) Please use speaker notes for additional information!
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Break Processing Please use speaker notes for additional information!
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Chapter 4: The Selection Process in Visual Basic.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Chapter 12: How Long Can This Go On?
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
Array - adding to array at run time Please see speaker notes for additional information!
Do Loop with Interest Please see speaker notes for additional information!
Input Textboxes Input Boxes Different than textboxes Good for small amount of input (form full of textboxes is not nice) X = Inputbox(“prompt message”,
New Project in Visual Basic Please use speaker notes for additional information!
Introduction to Programming with RAPTOR
Random Files Please see speaker notes for additional information!
Chapter Two Creating a First Project in Visual Basic.
Practical Programming COMP153-08S Week 5 Lecture 1: Screen Design Subroutines and Functions.
Two Forms Please use speaker notes for additional information!
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
VAT Calculator program Controls Properties Code Results.
Pay Example (PFirst98) Please use speaker notes for additional information!
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Maximum Profit Please use speaker notes for additional information!
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
31/01/ Selection If selection construct.
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.
Controlling Program Flow with Looping Structures
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Sorry, the pen lost control. Anyway, you need to download both the.vbp and the.frm for each project. I looked at PrCalc, I did not look at inventory.
Using a Database Access97 Please use speaker notes for additional information!
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
Chapter 6 Controlling Program Flow with Looping Structures.
Multiple forms - SDI & MDI Please use speaker notes for additional information!
Spreadsheet-Based Decision Support Systems
Please use speaker notes for additional information!
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Department Array in Visual Basic
We are starting to program with JavaScript
CIS16 Application Development and Programming using Visual Basic.net
If statements (Inven1, Inven2, Inven2a, Inven3, Inven3a)
Chapter 3: Selection Structures: Making Decisions
Using screens and adding two numbers - addda.cbl
Chapter 3: Selection Structures: Making Decisions
Presentation transcript:

Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!

PrArith Private Sub cmdCalculate_Click() Dim wknum1 As Single, wknum2 As Single, wkcalc As String Rem Process two numbers with +, -, *, or / and show the answer. picShow.Cls Call GiveDirections picShow.Print wknum1 = InputBox("Enter first number", "Entry 1",, 2000, 2000) wknum2 = InputBox("Enter second number - do not enter 0 if divide", "Entry 2",, 2000, 2000) wkcalc = InputBox("Enter +, -, *, /", "Entry process",, 2000, 2000) If wkcalc = "+" Then picShow.Print "The sum of"; wknum1; _ "and"; wknum2; "is"; wknum1 + wknum2 Else If wkcalc = "-" Then picShow.Print "The difference between"; wknum1; _ "and"; wknum2; "is"; wknum1 - wknum2 Else If wkcalc = "*" Then picShow.Print "Multiplying"; wknum1; _ "and"; wknum2; "results in"; wknum1 * wknum2 Else picShow.Print "Dividing"; wknum1; _ "by"; wknum2; "results in"; wknum1 / wknum2 End If End Sub Dim defines work variables to receive numbers as single and the variable to receive the sign as string. Rem is for remarks and picShow.Cls clears the picture box. Call will execute the routine GiveDirections and then return to continue processing.,, is where a default could be entered and 2000 are the x and y positions for the box. The line continuation character is the underscore preceded by a space. The If statement tests the input processing character entered in the third InputBox and stored as wkcalc.

PrArith Explains the InputBox. To Add a Procedure to your code, select Tools and then Add Procedure. A box will appear to allow you to name the procedure and specify certain features. Private Sub GiveDirections() End Sub This code is generated when you click OK.

PrArith Private Sub cmdCalculate_Click() Dim wknum1 As Single, wknum2 As Single, wkcalc As String Rem Process two numbers with +, -, *, or / and show the answer. picShow.Cls Call GiveDirections picShow.Print … End Sub Private Sub GiveDirections() Rem Explain the user input that is needed. picShow.Print "This program does a calculation." picShow.Print "Enter one number in the first input box." picShow.Print "Enter a second number in the second input box." picShow.Print "Do not enter 0 as the second number if dividing." picShow.Print "Pick +, -, *, / to pick the type of calculation." End Sub Call GiveDirections goes to the give direction subroutine and executes. When the code has been executed, it returns and starts processing with picShow.Print.

Private Sub cmdExit_Click() Call QuitMessage End End Sub Private Sub QuitMessage() Dim wkans As String picShow.Print "You have chosen to end processing." wkans = MsgBox("Processing will end", vbOKOnly, "Exit Box") End Sub PrArith When the Exit button is clicked, cmdExit_Click() is executed. The first thing is to Call QuitMessage. QuitMessage adds a line to the picture box and puts up a message box. When the user clicks OK on the message box, control returns to cmdExit_Click and the next command is executed. Since that is the End command, processing stops.

PrArith The main form appears in the center of the screen because of this setting.

PrArith When you run, the first screen appears. Clicking the Calculate button brings up the instructions and the request to enter the first number. I entered 17.

PrArith

The result is displayed. This ends the Calculate. The Exit button was clicked. A message is written in the picture box and the message box is displayed on the screen.

Math

projCP1 Three numbers are keyed in and added. The answer is stored in wrkAnswer. If wrkAnswer is over 100 than the subroutine Over100 is called and two variables are passed to it. One wrkAnswer and the other is an empty variable called wrkResult which will receive an answer from the called subroutine and pass it back when the processing in the subroutine is complete. It wrkAnswer is not over 100 than the subroutine NotOver100 is called and the same information is passed to it. After the call, the data is put on the form. In the subroutines subResult is calculated and when the routine is complete it will be passed back. wrkResult was passed back and is now going to the form.

projCP1 Private Sub cmdCalculate_Click() Dim wrkAnswer As Single, wrkResult As Single wrkAnswer = Val(txtNum1) + Val(txtNum2) + Val(txtNum3) If wrkAnswer > 100 Then Call Over100(wrkAnswer, wrkResult) Else Call NotOver100(wrkAnswer, wrkResult) End If txtAnswer = wrkAnswer txtResult = wrkResult End Sub Private Sub Over100(subAnswer As Single, subResult As Single) subResult = subAnswer * 1.05 End Sub Private Sub NotOver100(subAnswer As Single, subResult As Single) subResult = subAnswer * 1.1 End Sub wrkAnswer = = is not greater than 100 so NotOver100 is called and 57 is passed to it as wrkAnswer. wrkResult contains nothing. subAnswer * 1.1 = 57 *1.1 = 62.7 subResult is passed back and will be received as wrkResult are shown on the form

projCP1 Private Sub cmdCalculate_Click() Dim wrkAnswer As Single, wrkResult As Single wrkAnswer = Val(txtNum1) + Val(txtNum2) + Val(txtNum3) If wrkAnswer > 100 Then Call Over100(wrkAnswer, wrkResult) Else Call NotOver100(wrkAnswer, wrkResult) End If txtAnswer = wrkAnswer txtResult = wrkResult End Sub Private Sub Over100(subAnswer As Single, subResult As Single) subResult = subAnswer * 1.05 End Sub Private Sub NotOver100(subAnswer As Single, subResult As Single) subResult = subAnswer * 1.1 End Sub wrkAnswer = = is greater than 100 so Over100 is called and 200 is passed to it as wrkAnswer. wrkResult contains nothing. subAnswer * 1.05 = 200 *1.05 = 210 subResult is passed back and will be received as wrkResult are shown on the form

PrAdrProc cmdBreak calls SplitName and passes it the wkadr that was keyed in on the InputBox. In SplitName it is called subwkadr and is again defined as a string. I then use functions to break the name down into parts and display the parts on the form. Note that this information is put into the boxes in the subroutine. I could have passed back three additional items and put them in the form from cmdBreak.

PrAdrProc When Break Up Street Address is clicked, the InputBox appears. I keyed in an address following the instructions. Debugging boxes. The first shows. The first shows the location of the first space. The second shows the length of the street name. The breakup of the name.

PrAdrProcFunc Call SplitName(wkadr, wkstnum, wkstnam, wksttype) calls a procedure named SplitName and passes it the keyed in address as wkadr and empty variables that will receive data in the procedure. CombineName is a function that is passed wkstnum, wkstnam, wksttype. The results of the function are placed in txtWhole.

PrAdrProcFunc Subwkadr receives data from wkadr. The other fields defined after SplitName will hold the results of breaking up the address and will return the components to cmdBreak when the called procedure has finished executing.

PrAdrProcFunc txtWhole.Text = CombineName(wkstnum, wkstnam, wksttype) The statement above sends wkstnum, wkstname and wksttype to the function CombineName. They are then defined as fnwkstnum, fnwkstnam and fnwksttype with string type. CombineName is also a string type. After combining the name in funcName, funcName is assigned to CombineName. The function is now done and CombineName contains the combined address. Back in cmdBreak, CombineName is assigned to txtWhole on the form.

Private Function NewFunction() End Function