Download presentation
Presentation is loading. Please wait.
Published byEmory Owens Modified over 9 years ago
1
ME 142 Engineering Computation I Interacting with Spreadsheets
2
Key Concepts Getting Input from a Message Box Returning Program Output from a Message Box
3
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
4
InputBox Function
5
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 box’s title bar (optional) Default – defines the default value (optional) MyVar – variable which will receive the input entered
6
InputBox Function Examples Name = InputBox("Please enter your name: ","Name") MyNum = Val(InputBox("Enter the height:","Height"))
7
MsgBox Function
8
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 box’s title bar (optional) MyVar – variable receiving value of mouse click button (optional)
9
Example Problem Write a VBA program to calculate the surface area of a rectangular prism given the length, width, and height: As a Function, using the argument list As a Sub, reading from/writing to the spreadsheet As a Sub, using dialog boxes Modify the programs to also calculate the volume
10
MsgBox Function Examples MsgBox “Click OK to begin printing” Ans = MsgBox("Continue processing?", 4)
11
Values Used in MsgBox Function ValueConstant NameEnd Result 0 1 2 3 4 5 16 32 48 64 0 256 512 768 vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel vbCritical vbQuestion vbExclamation vbInformation vbDefaultButton1 vbDefaultButton2 vbDefaultButton3 vbDefaultButton4 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 Displays Critical Message icon Displays Warning Query Icon Displays Warning Message icon Displays Information Message icon First button is default Second button is default Third button is default Fourth button is default
12
Values Returned by the MsgBox Function ValueConstant NameMeaning 12345671234567 vbOK vbCancel vbAbort vbRetry vbIgnore vbYes vbNo User clicked OK User clicked Cancel User clicked Abort User clicked Retry User clicked Ignore User clicked Yes User clicked No
13
MsgBox Function Example: Display Yes/No buttons with exclamation point icon, default of no Button = vbYesNo +vbExclamation + vbDefaultButton2 Ans = MsgBox("Continue Processing?",Button)
14
Review Questions
15
Review Question InputBox Function What type of data does the InputBox function return? A.Integer B.Real C.String D.May return any of the above
16
Homework Help ‘n Hints
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.