ME 142 Engineering Computation I - PowerPoint PPT Presentation

About This Presentation
Title:

ME 142 Engineering Computation I

Description:

ME 142 Engineering Computation I Input, Output & Documentation Key Concepts Documentation Getting Program Input and Returning Program Output Linking a Program to a ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 16
Provided by: mille194
Learn more at: https://emp.byui.edu
Category:

less

Transcript and Presenter's Notes

Title: ME 142 Engineering Computation I


1
ME 142Engineering Computation I
  • Input, Output Documentation

2
Key Concepts
  • Documentation
  • Getting Program Input and Returning Program
    Output
  • Linking a Program to a Button

3
Header Example
  • Purpose
  • This program computes the hypotenuse of a
  • triangle, given the legs
  • Input
  • A, B legs of the triangle
  • Output
  • Hyp hypotenuse of the triangle
  • Author GS Miller
  • Date Created 10/15/2008
  • Limitations None

4
Improving Program Readability
  • Include Header
  • Use descriptive variable names
  • Use indentation and blank lines to clarify
    structure
  • Add other comments as appropriate

5
Getting Input/Returning Output
  • Via Functions
  • Passing Information to a Function via an Argument
    List
  • Returning Results from a Function to a Cell
  • Direct to/from a Spreadsheet
  • Reading Data from a Spreadsheet Cell
  • Returning Data to a Cell
  • Dialog Boxes
  • InputBox Function
  • MsgBox Function

6
Getting Input/Returning Output
  • VBA Supports 2 types of programs
  • Functions
  • Subprograms or Subroutines
  • Functions typically receive all of their input
    through the parameter list and write their output
    to the cell from which the function was launched
  • Subprograms may read/write directly to/from cells
  • Sub MyPgm()
  • End Sub

7
Using the Cells command to Read/Write Spreadsheet
Data
  • Data may be read from a spreadsheet cell using
    the cells command as shown below
  •   variable Cells(row,col)
  •  row,column the address of the cell to be read
  • variable name of variable which receives the
    contents of the cell

8
Using the Cells command to Read/Write Spreadsheet
Data
  • Data may be written to a spreadsheet cell using
    the cells command as shown below
  •   Cells(row,col) variable
  •  row,column - the address of the cell to be
    written
  • variable variable to be written to the cell

9
Using the Cells command to Read/Write Spreadsheet
Data
  • Example
  • Sub Square()
  • Acells(2,1)
  • BA2
  • cells(2,2)B
  • End Sub

10
Linking a Program to a Button
11
InputBox Function
  • Used to obtain a single value from the user
  • MyVar InputBox(prompt , title ,default)
  •  
  • Where
  • Prompt is the text displayed in the input box
    (required)
  • Title text displayed in the input boxs title
    bar (optional)
  • Default defines the default value (optional)
  • MyVar variable which will receive the input
    entered

12
InputBox Function
  • Examples
  • Name InputBox("Please enter your name
    ","Name")
  • MyNum Val(InputBox("Enter the height",
    "Height"))

13
MsgBox Function
  • Used to display information and get simple user
    input
  • MyVar MsgBox(prompt , buttons ,title)
  •  
  • Where
  • Prompt is the text displayed in the message
    box (required)
  • Buttons specifies buttons/icons appear in the
    message box (optional)
  • Title specifies the text displayed in the
    input boxs title bar (optional)
  • MyVar variable receiving value of mouse click
    button (optional)

14
MsgBox Function
  • Examples
  • Ans MsgBox("Continue processing?", vbYesNo)
  • MsgBox "Click OK to begin printing"

15
Common MsgBox Function Constants
Constant Name End Result
vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel Displays OK Button only Displays OK and Cancel buttons Displays Abort, Retry, and Ignore buttons Displays Yes, No, and Cancel buttons Displays Yes and No buttons Displays Retry and Cancel buttons
Write a Comment
User Comments (0)
About PowerShow.com