1. Reminder of Symbols 2. Dialog Boxes 3. listdlg() 4. msgbox() 5. questdlg() 6. menu() Dialog Boxes Applications of Cell-Arrays 1.

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

Microsoft® Access® 2010 Training
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Using Macros and Visual Basic for Applications (VBA) with Excel
Click here to enter. Click a menu option to view more details Starters Main Courses Desserts Click on the coffee cup to return when Navigating For Vocabulary.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
1. Definition 2. Creating Cell Arrays 3. Augmenting Cell Arrays 4. Referencing Cell Arrays 5. Special case 6. Spreadsheets 1.
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
1 Excel Lesson 4 Entering Worksheet Formulas Microsoft Office 2010 Introductory Pasewark & Pasewark.
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms Psych 209.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Exploring Formulas.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Computer Literacy BASICS
Programming a GUI Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
CTS130 Spreadsheet Lesson 5 Working with Simple Formulas.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
Actilab Pharma Online Services User Manual June 2004.
1 Functions Advantages Name, parameters, return info Flow of the data when running functions Menus Functions Applying Functions to Real Projects.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
MICROSOFT WORD GETTING STARTED WITH WORD. CONTENTS 1.STARTING THE PROGRAMSTARTING THE PROGRAM 2.BASIC TEXT EDITINGBASIC TEXT EDITING 3.SAVING A DOCUMENTSAVING.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
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.
GUI Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Cell Arrays 1. Data Types (Review) 2. General Concept 3. Creating Cell Arrays 4. Augmenting Cell Arrays 5. Referencing Cell Arrays 1. The entire cell/
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
1. Definition and General Structure 2. Small Example 1 3. Simplified Structure 4. Short Additional Examples 5. Full Example 2 6. Common Error The for loop.
1.Reminder of Symbols 2.Dialog Boxes 3.Output-centric dialogs 4.Input-centric dialogs Dialog Boxes Applications of Cell Arrays 1.
Using Client-Side Scripts to Enhance Web Applications 1.
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
CPS120: Introduction to Computer Science Decision Making in Programs.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
JavaScript, Fourth Edition
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
LANDESK SOFTWARE CONFIDENTIAL Tips and Tricks with Filters Jenny Lardh.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
Cell Arrays Lecture 2/8/ Data Types (Review) 2. General Concept 3. Using Cell-Arrays 1. Syntax/Symbols 2. Dialog Boxes 1.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
31/01/ Selection If selection construct.
1. Comparing Strings 2. Converting strings/numbers 3. Additional String Functions Strings Built-In Functions 1.
1. Normal arrays of characters 2. Converting a list of strings to a cell- arrays of strings 3. Converting a cell-array of strings to a list of strings.
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.
1 4.2 Selection Logical Operators. 2 Learning Objectives Explain how the logical operator AND Boolean statements works. Directly testing if text boxes.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Fundamentals of Windows Mouse n 4 Basic Operations: –Pointing –Clicking –Double Clicking –Dragging.
ME 142 Engineering Computation I
Dialog Boxes Applications of Cell-Arrays
More on Graphical User Interfaces
Predefined Dialog Boxes
More Selections BIS1523 – Lecture 9.
T. Jumana Abu Shmais – AOU - Riyadh
CIS 16 Application Development Programming with Visual Basic
Presentation transcript:

1. Reminder of Symbols 2. Dialog Boxes 3. listdlg() 4. msgbox() 5. questdlg() 6. menu() Dialog Boxes Applications of Cell-Arrays 1

1. Reminders on Symbols Creating/hard-coding: Braces { } Referencing to content:Braces { } Augmenting:Brackets [ ] Referencing to container: Parentheses () Most likely to be used! 2

2. Dialog Boxes 33

Dialog boxes are “popup windows” that allows us another means to communicate with the user. Some dialog boxes to collect input: inputdlg(), listdlg(), menu(), questdlg() And some to produce output: msgbox(), warndlg() 99% of the time, the command deals with cell arrays, either as arguments, as return-values, or both! 44

3. listdlg() listdlg() – Create and open list-selection dialog box Major Advantage: User does not have to type anything  Less spelling errors! 5

>>doc listdlg() This function returns 2 return-values. 6

[Selection,ok] = listdlg('ListString',S) Selection is a vector of indices of the selected strings (in single selection mode, its length is 1). Selection is [] when ok is 0. ok is 1 if you click the OK button, or 0 if you click the Cancel button or close the dialog box. Double-clicking on an item or pressing Return when multiple items are selected has the same effect as clicking the OK button. The dialog box has a Select all button (when in multiple selection mode) that enables you to select all list items. 7

listdlg() return-values What will the first return- value be after this executes? a. {'Primary Booster','Secondary Boosters'} b. [1 3] c. {1, 3} d. None of the above 8

[Selection,ok] = listdlg('ListString',S) Selection is a vector of indices of the selected strings (in single selection mode, its length is 1). Selection is [] when ok is 0. ok is 1 if you click the OK button, or 0 if you click the Cancel button or close the dialog box. Double-clicking on an item or pressing Return when multiple items are selected has the same effect as clicking the OK button. The dialog box has a Select all button (when in multiple selection mode) that enables you to select all list items. If user hits cancel or closes the dialog box, an empty-vector is returned, AND ok is set equal to 0. This means the second return-value can be used to see what the user did! 9

What did user do? Did user hit ok? Did user hit cancel? Either way: Had s/he selected anything anyway?  If user did click ok, then ok will be true, which equals 1.  If user did not click ok, then ok will be false, which equals 0. 10

Inputs are in parameter/value pairs (i.e. they go 2 by 2): Parameter goes 1st, value of the parameter goes 2nd. [Selection,ok] = listdlg('ListString',S) The actual string: 11

myList is a CELL ARRAY of string: { } Why cell arrays? The length of each selection varies widely, and an regular-array would not be rectangular. Experiment in the command window! 12

Experiment in the command window! What button did the user hit? a. The 'ok' button b. The 'cancel' button c. The [x] that closes the window d. Either b or c e. None of the above 13

A second parameter Though additional arguments are not necessary, you may choose to add them AS A PAIR. For example: 14

2nd PAIR of inputs. 15 The Select All button is gone.

2nd PAIR of inputs. 16 What did the user select? a. It cannot be determined b. __________________________

17

3.a. Full Example Create a software that estimates the time an aircraft takes to travel a certain distance. Aircrafts possible, with their average speeds are: 1) Cessna 150, 198 kmph 2) Boeing 787, 950 kmph 3) Concorde,2147 kmph 4) Cessna 421,444 kmph 18

Algorithm %prompt user for type of airplane (error?) %prompt user for distance to travel (error?) %calculate/display Presented is the evolution from: Option1: use input() and if. (week 2,3.4) Option2: use input() and vectors. (week 10) Option3: using listdlg(), vectors and cell-arrays. 19

#1. input(), if and while %prompt user for type of airplane type = input('Enter the type of airplane: \n1 – cessna 150\n 2-Boeing 787\n3-Concorde\n4-Cessna 421\n Enter now: '); %prompt user for distance to travel distance = input('Enter the distance (km): '); %calculate/display if type == 1 %cessna 150 travelTime = distance/198; fprintf('With this plane, it will take %.2fhrs.\n', travelTime); elseif…. 20 Add while loops to trap errors.

#2. input(), vectors, while %prompt user for type of airplane type = input('Enter the type of airplane: \n1 – cessna 150\n 2-Boeing 787\n3-Concorde\n4-Cessna 421\n Enter now: '); %prompt user for distance to travel distance = input('Enter the distance (km): '); %data base of speeds speeds = [198, 950, 2147, 444]; %calculate/display travelTime = distance/speeds(type); fprintf('With this plane, it will take %.2fhrs.\n', travelTime); 21 Add while loops to trap errors. Reference the correct value in the vector, using the index.

#3. listdlg(), arrays, while %prompt user for type of airplane myPlanes = {'Cessna 150', 'Boeing 787', 'Concorde', 'Cessna 421'}; type = listdlg('ListString', myPlanes,'selectionmode', 'single'); %prompt user for distance to travel distance = inputdlg('Enter the distance (km): '); %data base of speeds speeds = [198, 950, 2147, 444]; %calculate/display travelTime = distance/speeds(type); fprintf('With this plane, it will take %.2fhrs.\n', travelTime); 22 Add while loop to trap errors, and convert to number Reference the correct value in the vector, using the index.

#3. Output Note: once a software starts with dialog boxes, it should end with dialog boxes… >> not in the command window..  23

4. msgbox() A little improvement: %calculate/display travelTime = distance/speeds(type); resultString = sprintf('With this plane, it will take %.2fhrs.\n', travelTime); msgbox(resultString) 24

4. msgbox() A little improvement: %calculate/display travelTime = distance/speeds(type); resultString = sprintf('With a %s, it will take %.2fhrs.\n', ??????, travelTime); msgbox(resultString) 25 Task: Replace "this plane" by the actual name!

4. msgbox() %prompt user for type of airplane myPlanes = {'Cessna 150', 'Boeing 787', 'Concorde', 'Cessna 421'}; type = listdlg('ListString', myPlanes,'selectionmode', 'single'); Remember: this is the index (i.e. location) of the string selected. This is the cell-array of all the names. To reference the name selected using the index selected: planeSelected = myPlanes{type}; 26 REFERENCE the CONTENT, using curly braces.

4. msgbox() A little improvement: %calculate/display travelTime = distance/speeds(type); resultString = sprintf('With a %s, it will take %.2fhrs.\n', myPlanes{type}, travelTime); msgbox(resultString) 27

Make the software error proof! %prompt user for type of airplane myPlanes = {'Cessna 150', 'Boeing 787', 'Concorde', 'Cessna 421'}; [type ok] = listdlg('ListString', myPlanes,'selectionmode', 'single'); %if user hits ok, continue if ok==1 %prompt user for distance to travel distance = inputdlg('Enter the distance (km): '); %code as before else %user hit cancel of closed box.. %do other stuff end 28

Done with that example. Note how much a software has improved since your first knowledge of week2, and yet not too many lines of code were required. Hopefully, you're pausing and coding this in parallel. Use them in the final project if you want. Make sure to error-proof accordingly. 29

5. questdlg() Typical call: button = questdlg('qstring','title','str1','str2', 'str3','default') qstring = Question to ask the user title = Title for dialog box str1 = String to show on Button #1 str2 = String to show on Button #2 str3 = String to show on Button #3 default = String that is the default button button = string on the button that was clicked Caution: Maximum of 3 buttons. 30

5. Quick experiment button = string on the button that was clicked 31

6. menu() – vertical menu Typical call: button = menu('qstring','bt1','bt2',……,'btn') qstring = question to ask user bt1 = String to show on Button #1 bt2 = String to show on Button #2 Can have as many options as desired. There is no default answer. Return value: Button number clicked (not the string) 32

6. menu(), with cell-arrays 33

6. Output 34

What's next??? Yes, we are done with cell-arrays and dialog boxes.. So what's next? Files! 35

Wrapping Up Dialog boxes are user friendly but time taking Dialog boxes should not be used when the software is not meant to be sold. Lots of clicking vs. entering data in the command window. Choose carefully. We saw: inputdlg() listdlg() msgbox() questdlg() menu() NEVER learn the syntax by heart. Practice it enough, then use the doc to remind yourself quickly! 36