210 likes | 328 Views
CN2180 Chapter 3. Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP. Agenda. VBScript Basics Assignment Quiz. VBScript Statements. Table 3.1 on page 51 - 52. VBScript Syntax Rules. By default, all VBScript statements must fit on one line.
E N D
CN2180Chapter 3 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP
Agenda • VBScript Basics • Assignment • Quiz
VBScript Statements • Table 3.1 on page 51 - 52
VBScript Syntax Rules • By default, all VBScript statements must fit on one line. • _ (Continuation) character is an exception to have more than one line statement • : (Colon) character is used to put more than one statement on a single line
VBScript Syntax Rules (Cont.) • Option Explicit : • To make sure that you declare variables • To troubleshoot by generating errors to highlight mistakes if variable names are mistyped later in the script • The text book is NOT properly stated. • See page 52 for more information
Reserved Words • Table 3.2 on page 54
Adding Comments • Two ways to add comments • Rem (Remark) • ‘ • A good practice example on page 55
VBScript Object Model • Besides WSH Core Object Model, there are Built-in objects as well • Table 3.3 on page 56 • See chapter 11.
VBScript Run-Time Objects • To interface with the windows resources • See Table 3.4 on page 57
VBScript Run-Time Objects • FileSystemObject object is needed. • You can check the existence of files and folder before attempting to work with them • Create and delete files and folders. • See page 58.
VBScript Run-Time Objects • Table 3.5 on Page 58 provides a complete list of VBScript run-time properties. • Table 3.6 on Page 60provides a list of VBScript run-time method.
VBScript Run-Time Objects • See code on page 61.
Built-in VBScript Functions • There are a lot of built-in function • InputBox() • MsgBox() • Sqr() • See Appendix D on page 417. • See code on page 64.
Displaying Script Output • There are 4 options to display output • Echo() • Popup() • InputBox() • MsgBox()
Echo() Method • Wscript.Echo [Arg1] [,Args2] …
Popup() Method Set WshShl = Wscript.CreateObject(“Wscript.Shell”) • Two syntax of Popup() Response = Wscript.Popup(StrText,[Time],[TitleBarMsg],[DialogSettings]) Wscript.PopupStrText,[Time],[TitleBarMsg],[DialogSettings] • See Table 3.8 and 3.9 for Dialog Settings • Table 3.10 lists the range of values of Response
InputBox() Function Response = InputBox (StrText[, TitleBarMsg][, default][, xpos][, ypos][, helpfile, context])
MsgBox() Function • MsgBox (TextMsg[, buttons][, TitleBarMsg][, helpfile, context]) • See Table 3.11 and 3.12 for buttons option on page 70 • See Table 3.13 for possible outcome on page 71
SendKeys() method • This method is used to send keystrokes to currently active Windows application • See Table 3.14 on page 73 and Table 3.15 on page 74
Let’s the game begin! • Page 74
Assignment • Challenges #1 : Modified the script to solve the equation 10 – 5 * 3 / Sqr(10) – 1 • Challenges #2 : Show input box to ask for your name. Then use script to open notepad and type “My name is “ & your name