210 likes | 325 Vues
This chapter covers the fundamentals of programming, focusing on flowcharts and pseudocode. It introduces concepts such as the Windows Script Host (WSH) and VBScript. Readers will learn how to create flowcharts and write pseudocode for tasks like a grading system and a "Knock Knock" game. Key topics include defining processes, conditions, and user input handling. This material is designed for those pursuing a foundational understanding of scripting in Windows environments, emphasizing practical assignments for hands-on learning.
E N D
CN2180Chapter 1 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP
Agenda • Introduction to programming • Basic Flow Chart • Basic Pseudo code • Introduction to WSH and VBScript • Assignment
Introduction to programming • What is flowchart? • Why we need it? • What does it look like?
Basic flow chart • Start / Stop (End) • Process • Condition (Yes / No) • Input • Display
Basic flow chart (cont.) Start How are you? input yes No =“good”? X = “Excellent!” X = “I’m sorry” ‘X’ Stop
Basic Pseudo code • What is Pseudo code? • Why we need it? • What does it look like?
Basic Pseudo code (Cont.) • Start • Ask user, “How are you” • Take input from user • If input = “good” then • X := “Excellent!” • Else • X := “I’m sorry” • Display “X” • Stop
Exercise • Write a flow chart and pseudo code for • Grading system • Take input from user • Show A, if input is greater than or equal to 90
Introduction to WSH • Windows Script Host (WSH) • Run on MS Windows • Small text based file • WSH Components • Script Engines • Script execution hosts • The WSH core object model • See Figure 1.5 on page 5
WSH Scripting Engines • Script execution engine • VBScript • Jscript • 3rd party script engines such as Perl, Python, and Rexx.
WSH Script Execution Host • CScript.exe • WScript.exe • Which one you should use? • Required user interaction?
WSH Core Object Model • It provides VBScript with direct access to Windows resources • Windows desktop • Windows Start menu • Windows applications • Windows file system
Object, Method, and Properties • What is an Object? • Object has method and properties • IE. Box is an object • Box’s method are put it in, take it out, re-arrange • Box’s properties are height, width, water resistance, etc
First VBScript • Type : MsgBox “Hello World!” • Save it as hello.vbs • By default, windows use wscript.exe to execution host
First VBScript (Cont.) • MsgBox() function is a built-in VBScript function • Modified the code to: Set WshShl = Wscript.CreateObject(“Wscript.Shell”) WshShl.Popup “Hello World!”
First VBScript (Cont.) • Set is to define a variable named WshShl with a value Wscript.CreateObject(“Wscript.Shell”) • CreateObject method is used to instantiate the WshShell object. • Popup() method is to display a pop-up dialog
First VBScript (Cont.) • Modified the code: WScript.Echo “Hello World” • Echo() method is to display a text message. • Tried with both WScript and CScript.
Knock Knock Game • Designing the game: • Knock Knock! -> Who’s There • Panther -> Panther who? • Panther no panths, I’m going swimming • Error message should be displayed if answered wrong
Knock Knock Game (Cont.) • Write pseudo code or draw flow chart • Do the code.
Knock Knock Game (Cont.) Reply1 = InputBox(“Knock Knock!”) If Reply1 = “Who’s there?” Then Reply2 = InputBox(“Panther!”) If Reply2 = “Panther who?” Then MsgBox “Panther no panths I’m going swimming.” If Reply2 <> “Panther who?” Then MsgBox “Incorrect answer. Try again.” End if If Reply1 <> “Who’s there?” Then MsgBox “Incorrect answer. Try again.”
Assignment • P29 Challenges #3 • Write a script to take input (name and grade) from user then use message box to show name, grade, and grade letter.