Presentation is loading. Please wait.

Presentation is loading. Please wait.

CN2180 Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.

Similar presentations


Presentation on theme: "CN2180 Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP."— Presentation transcript:

1 CN2180 Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP

2 Agenda Constants, Variables, Arrays, and Dictionaries. The Story of Captain Adventure Assignment Quiz Constants, Variables, Arrays, and Dictionaries. The Story of Captain Adventure Assignment Quiz

3 How data is defined Three ways to define or declare variable –Const –Dim –Redim Three ways to define or declare variable –Const –Dim –Redim

4 Constant User defined Built-in –vbTab –vbCrlf User defined Built-in –vbTab –vbCrlf

5 Assigning Data to Constants [public | private] Const ConstName = Expression See Table 4.3 on Page 84 See MsgFormatter.vbs on Page 84 [public | private] Const ConstName = Expression See Table 4.3 on Page 84 See MsgFormatter.vbs on Page 84

6 VBScript Data Types There are only one type called a variant –Boolean –Date –String See table 4.4 on Page 90 There are only one type called a variant –Boolean –Date –String See table 4.4 on Page 90

7 Defining Variables Dim variable name Assign a value Option Explicit –See BigBadWolf.vbs on Page 92 Dim variable name Assign a value Option Explicit –See BigBadWolf.vbs on Page 92

8 Variable Naming Rules Less than 256 characters long Must begin with an alphabetic character Only letters, numbers, and _ allowed Reserved words cannot be used Space is not allowed Must be unique Less than 256 characters long Must begin with an alphabetic character Only letters, numbers, and _ allowed Reserved words cannot be used Space is not allowed Must be unique

9 Hungarian Notation Add three characters in front of variable name –Date = dtm –Error = err –Object = obj –String = str –See Page 95 Add three characters in front of variable name –Date = dtm –Error = err –Object = obj –String = str –See Page 95

10 Modifying Variable Values Dim strMyName strMyName = “Kemtis” strMyName = “Kunanuraksapong Dim strMyName strMyName = “Kemtis” strMyName = “Kunanuraksapong

11 Arithmetic Operations See MathDemo.vbs on Page 97

12 Order of Precedence ^ - Exponential -- Negation *-Multiplication /-Division \-Integer division Mod-Modulus +-Addition --Subtraction ^ - Exponential -- Negation *-Multiplication /-Division \-Integer division Mod-Modulus +-Addition --Subtraction

13 Environment Variables What is environment variables? TEMP TMP See ComputerAnalyzer.vbs on Page 101 What is environment variables? TEMP TMP See ComputerAnalyzer.vbs on Page 101

14 A collections of related data Array –Index –Value Dim ArrayName(dimensions) Dim ArrayName(dimensions,dimensions) Array –Index –Value Dim ArrayName(dimensions) Dim ArrayName(dimensions,dimensions)

15 Processing Array Contents For Each element In group Statements…. Next [Element] See ArrayDemo.vbs on Page 106 For Each element In group Statements…. Next [Element] See ArrayDemo.vbs on Page 106

16 Getting a handle on the size Ubound() Lbound() Ubound() Lbound()

17 Resizing Arrays Dim astrMyArray () Redim astrMyArray (10) Redim Preserve astrMyArray(20) See ResizeArray.vbs on Page 110 Dim astrMyArray () Redim astrMyArray (10) Redim Preserve astrMyArray(20) See ResizeArray.vbs on Page 110

18 Erasing Array Erase ArrayName

19 Dictionaries Just like Array –Define own pair of key and value Three properties –Count (Return number of object) –Item (Get or Add an item) –Key (Add new key) Just like Array –Define own pair of key and value Three properties –Count (Return number of object) –Item (Get or Add an item) –Key (Add new key)

20 Dictionaries (Cont.) Dictionaries method Add (Add key/item) Exists (Boolean / True if exist) Items (Return all Items) Keys (Return keys) Remove (Delete a key/item pair) Remove All (Remove all key/item pairs) Dictionaries method Add (Add key/item) Exists (Boolean / True if exist) Items (Return all Items) Keys (Return keys) Remove (Delete a key/item pair) Remove All (Remove all key/item pairs)

21 Work with Dictionary Dim dictObject Set dictObject = CreateObject(“Scripting.Dictionary”) dictObject.Add “Model1555”,”Red Bike” dictObject.Add “Model1888”,”Blue Bike” dictObject.Item(“Model1999”) = “Green Bike” If dictObject.Exists(“Model1555”) = true then _ msgbox “Model 1555 is a “ & dictObject.Item(“Model1555”) dictObject.Remove “Model1555” dictObject.removeall Dim dictObject Set dictObject = CreateObject(“Scripting.Dictionary”) dictObject.Add “Model1555”,”Red Bike” dictObject.Add “Model1888”,”Blue Bike” dictObject.Item(“Model1999”) = “Green Bike” If dictObject.Exists(“Model1555”) = true then _ msgbox “Model 1555 is a “ & dictObject.Item(“Model1555”) dictObject.Remove “Model1555” dictObject.removeall

22 Parsing Arguments Must run with cscript.exe cscript displayargs.vbs tic tac toe cscript displayargs.vbs tic “super tac” toe See ArgumentProcessor.vbs on Page 116 Must run with cscript.exe cscript displayargs.vbs tic tac toe cscript displayargs.vbs tic “super tac” toe See ArgumentProcessor.vbs on Page 116

23 Captain Adventure game Beginning the captain Adventure script Setting up Constants and Variables Creating a splash Screen Collecting User Input Assembling and Displaying the story Beginning the captain Adventure script Setting up Constants and Variables Creating a splash Screen Collecting User Input Assembling and Displaying the story

24 Assignment Challenge #1 Add 2 more user input and adding more story to the story line. Challenge #2 Use an Array to store the user input collected instead. Challenge #1 Add 2 more user input and adding more story to the story line. Challenge #2 Use an Array to store the user input collected instead.


Download ppt "CN2180 Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP."

Similar presentations


Ads by Google