1 / 24

CN2180 Chapter 4

CN2180 Chapter 4. Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP. Agenda. Constants, Variables, Arrays, and Dictionaries. The Story of Captain Adventure Assignment Quiz. How data is defined. Three ways to define or declare variable Const Dim Redim. Constant.

missy
Download Presentation

CN2180 Chapter 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CN2180Chapter 4 Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP

  2. Agenda • 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

  4. Constant • 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

  6. VBScript Data Types • 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

  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

  9. Hungarian Notation • 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

  11. Arithmetic Operations • See MathDemo.vbs on Page 97

  12. Order of Precedence • ^ - 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

  14. A collections of related data • 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

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

  17. Resizing Arrays • Dim astrMyArray () • RedimastrMyArray (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)

  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)

  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

  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

  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

  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.

More Related