Class 1 - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Class 1

Description:

If ( InputData = vbYes ) then wscript.echo 'Yes, it is a nice day' ... arrAnswer(vbYes) = 'Yes, it is a nice day' arrAnswer(vbNo) = 'I agree, it's a lousy day' ... – PowerPoint PPT presentation

Number of Views:94
Avg rating:3.0/5.0
Slides: 18
Provided by: JerryBr
Category:
Tags: class | nice

less

Transcript and Presenter's Notes

Title: Class 1


1
Old Business Registration Next Week HOW TO USE
THESE NOTES!!
Where Are We Going Today? Reviewing last
time Variables, Constants, and Arrays Flowchart
for Pick The Last Coin Coding for Pick The
Last Coin
Review Input Boxes, etc.
2
(No Transcript)
3
Subroutines '
' This shows
how to use a subroutine A subroutine is simply
a package that does some work in an organized
way. '
Option Explicit Dim
var1, var2, var3, var4 var1 "Computers are
fun WScript.Echo "this is var1 -, var1 call
MySubroutine1( var1, var2, var3,
var4) WScript.Echo "this is var2 - ", var2, "
var3 - ", var3, " var4 - ", var4 '

' This is the subroutine '

Sub MySubroutine1( subvar1,
subval2, subval3, subval4 ) Dim
mystring mystring split( subvar1, " " )
subval2 mystring(0) subval3
mystring(1) subval4 mystring(2) End Sub
4
Variables '
' Shows use of
Variables - Pages 32 - 34 and 69 - 74 '

Sub DemoVariables Dim
intVariable ' Integer - These are "visible
only in sub Dim strVariable ' String
Dim dtmNow ' Date/Time Dim intVar2,
strVar2, dtmNextMonth ' Several vars on one
line intVariable 42 intVar2
10 strVariable "This is
a String of characters" strVar2
"And Still More String" dtmNow
now Wscript.Echo "Printing out the variables
we've defined" Wscript.Echo "INT ",
intVariable, " DATE ", dtmNow, " STRING ",
strVariable intVariable intVariable
intVar2 strVariable strVariable " "
strVar2 dtmNextMonth DateAdd( "M", 1,
dtmNow ) Wscript.Echo "INT " intvariable
" DATE " dtmNextMonth Wscript.Echo
"STRING ", strVariable strVar2 "10"
Wscript.Echo "What happens when we combine
variables?" Wscript.Echo CInt( strVar2 ),
CInt( strVar2 ) 2 Wscript.Echo strVar2 2,
strVar2 "2" End Sub
5
Constants '
' Shows use of
Constants - Pages 76 - 79 '
Sub
DemoConstants Const SCHOOL_NAME "Clark
University" Const MAX 10
Wscript.Echo "Print out some constants"
Wscript.Echo SCHOOL_NAME, " Red ", vbRed, "
Monday ", vbMonday WScript.Echo "Default 1
", vbDefaultButton1, "Yes ", vbYes End Sub
6
'
' Shows use of Arrays -
Pages 44
Sub DemoArrays Dim
arrOneDim(10), arrAnswer(20), Buttons, InputData,
WeekArray, Today arrOneDim(0) 42
arrOneDim(10) 142 arrOneDim(11) 842
Wscript.Echo arrOneDim(0), " ", arrOneDim(10)
' This is the way we did it before
Buttons vbYesNoCancel vbQuestion
vbDefaultButton2 InputData MsgBox( "Is this a
nice day?", Buttons, "Nice Day Box" ) If (
InputData vbYes ) then wscript.echo "Yes, it
is a nice day" If ( InputData vbNo ) then
wscript.echo "I agree, it's a lousy day" If (
InputData vbCancel ) then wscript.echo "Yes,
let's erase this day!" ' This is a new easier
way arrAnswer(vbYes) "Yes, it is a nice
day" arrAnswer(vbNo) "I agree, it's a
lousy day" arrAnswer(vbCancel) "Yes, let's
erase this day!" Buttons vbYesNoCancel
vbCritical vbDefaultButton2 InputData
MsgBox( "Is this a nice day?", Buttons, "Nice Day
Box" ) wscript.echo arrAnswer(InputData)
WeekArray Array("Sunday", "Monday", "Tuesday",
"Wednesday", _ "Thursday",
"Friday", "Saturday") Today weekarray(Weekday(N
ow)) InputData InputBox( "What Day Is It??",
"Get-The-Day-Box", Today, 6000, 0 ) End Sub
ARRAYS
7
DETOUR -- VB Script on a Webpage TITLETest Button Events ORM NAME"Form1" NAME"Button1" VALUE"Click" FOR"Button1" EVENT"onClick" LANGUAGE"VBScript"
MsgBox "Button Pressed!"
My script is
called ScriptInHtml.html
8
Operators '
' Shows use of
Operators - Pages 34 - 43 '
S
ub DemoOperators Wscript.Echo "Showing
the use of operators" Wscript.Echo "1 4
10 6 - 4 / 2 ", 1 4 10 6 - 4 / 2
Wscript.Echo "(1 4 10) 6 - (4 / 2) ",
(1 4 10) 6 - (4 / 2) Wscript.Echo "1
4 10 (6 - 4) / 2 ", 1 4 10 (6 - 4)
/ 2 Wscript.Echo "(1 4 10) (6 - 4) / 2
", (1 4 10) (6 - 4) / 2 Wscript.Echo
"1 4 10 (6 - 4) / 2 ", 1 4 10 (6
- 4) / 2 Wscript.Echo "Hello World
", "Hello" " World" Wscript.Echo
"True, False ", True, False
Wscript.Echo "True AND True ",
True AND True Wscript.Echo "True OR False
", True OR False Wscript.Echo "7
AND 4 ", 7 AND 4
Wscript.Echo "1 4 10 (6 - 4) / 2 ", 1
4 10 (6 - 4) / 2 Wscript.Echo "Hello World ", "Hello" 9
'
' Shows use of Conditionals
- Pages 46 - 50 '
Sub
DemoConditionals Dim intVar, FirstColor,
SecondColor intVar 4 If ( intVar
3 ) Then Wscript.Echo "The value is
greater than or equal to 3" ElseIf ( intVar
1 ) Then Wscript.Echo "The value is equal
to 1" Else Wscript.Echo "The value is
something else" End If FirstColor
"RED" SecondColor "BLUE" If (
FirstColor "RED" And SecondColor "BLUE") Then
WScript.Echo "The color is purple"
Else WScript.Echo "The color is NOT purple"
End If Select Case FirstColor Case
"red" Wscript.Echo "Red" Case "green"
Wscript.Echo "Green" Case "blue"
Wscript.Echo "Blue" Case Else
Wscript.Echo "pick another color" End
Select End Sub
Control Flow - Conditionals
10
'
' Shows use of Loops -
Pages '
Sub DemoLoops
Dim intVar Dim strArg, arrArgs
Wscript.Echo "Showing the use of loops" For
intVar 5 to 0 step -1 Wscript.Echo
"Count Down - " intVar if ( intVar 0
) Then Wscript.Echo "Blast Off!!"
End If Next if WScript.Arguments.Coun
t 0 Then WScript.Echo "Please enter
multiple arguments for this demo" WScript.Quit
End If Set arrArgs WScript.Arguments
For Each strArg in arrArgs Wscript.Echo
"Argument ", intVar, " is ", strArg
intVar intVar 1 Next
Control Flow - Loops I
11
' Example of do while .. loop intVar
0 Do While ( intVar intVar 10 ) Then Wscript.Echo "Found a match
1" intVar intVar 1 Loop
intVar 10 Do While ( intVar If ( intVar 10 ) Then Wscript.Echo "Found a
match 2" intVar intVar 1 Loop
' Example of do loop .. while intVar 10
Do If ( intVar 10 ) Then
Wscript.Echo "Found a match 3" intVar
intVar 1 Loop While ( intVar intVar 0 While intVar "Value in While .. Wend is ", intVar intVar
intVar 1 if ( intVar 3 ) Then intVar
20 Wend End Sub
Control Flow - Loops II
12
Flow Charts Produce a flow chart for the game
"Pick the last coin" Variables used
are StartingNumberOfCoins, MaxPerTurn,
WhoGoesFirst CurrentCoins TargetCoins
Get Inputs
Calculate Target Coins
Yes
Choose Number of Coins
My Turn?
No
Yes
Your Turn?
Get Users Choice
No
Figure Out who won - Applaud
Done
No
Yes
13
'
' This is a game called
"Pick the last coin" '
Opt
ion Explicit Dim StartingNumberOfCoins,
MaxPerTurn, WhoGoesFirst Dim CurrentCoins,
TargetCoins, WhoseTurn Dim Temp, Answer '

' GET
IMPUTS '
WScript.Echo "This is a
game pitting you against the computer." WScript.Ec
ho "The object is to pick up the last
coin." StartingNumberOfCoins InputBox( "How
many coins do you want to start with?"
) MaxPerTurn InputBox( "What's the max coins
you can take on a turn?" ) WhoGoesFirst MsgBox(
"Do You Want To Go First?", 4 ) WScript.Echo
"Starting Coins ", StartingNumberOfCoins, " Max
Per Turn ", MaxPerTurn '
'
ANALYZE WHO GOES FIRST '

If ( WhoGoesFirst vbYes )then
WScript.Echo "You go first." WhoseTurn
"Yours" End if If ( WhoGoesFirst vbNo )then
WScript.Echo "I go first." WhoseTurn
"Mine" End if
Pick Up Coins I
14
' Set up the starting value and what we want to
first aim at CurrentCoins StartingNumberOfCoins
While ( CurrentCoins 0 ) '

' CALCULATE
TARGET COINS '
Temp
int(CurrentCoins / ( MaxPerTurn 1 ) )
TargetCoins Temp ( MaxPerTurn 1 ) If (
WhoseTurn "Mine" ) Then '

' DETERMINE NUMBER
CHOSEN BY COMPUTER '
Else
'
'
Get NUMBER CHOSEN BY USER '

End if CurrentCoins
CurrentCoins - Answer WScript.Echo "Number
Remaining is ", CurrentCoins '

' FIGURE OUT WHO WON --
APPLAUD '
If (
CurrentCoins 0 ) Then ' We're done!!
If ( WhoseTurn Yours ) Then WScript.Echo "You
Win! Congratulations!!" If ( WhoseTurn
Mine ) Then WScript.eco "I Win! Thanks for
playing" End If If ( WhoseTurn "Yours"
) then WhoseTurn "Mine" Else
WhoseTurn "Yours" End if wend
Pick Up Coins I
15
  • Assignment For Next Class
  • Use the examples we learned today to improve on
    the dialog. Use arrays, conditionals, and
    whatever else you find useful.
  • What is your name?
  • And how are you feeling today Johnny?
  • Im happy to hear that youre feeling sunny!
  • Right now the "Pick the last coin game loops
    infinitely. Start filling in the missing pieces
    to make this game work.

16
Topics To Be Included Here
Computer Languages VBS Pros and Cons. Command
Line notepad Type Dir Makedir Help notepad
Text editor VBS Environment - 10 Using
Hello World - 15 Wscript Cscript Syntax Host
Options Language Essentials 25 REM and
! Variables a is an int, string, or
double Wscript.Echo Wscript.Quit Dim and
Option Explicit 32 Line Continuation use of
_
How to use comments GUI IO 121 InputBox,
MsgBox Numbers, Strings, Variables
32 Expressions and Assignments 34 X x
1 Operators 35 Arithmetic, String, Comparison,
Logical Parenthesis 39 Program Arguments
30 Sample Program 43 Arrays 44 Control Flow
46 Conditional Statements If 47 If then
else 48 If then elseif .. else .. 48 If
then .. end if - 48
17
Topics To Be Included Here
Loops Do while Loop 50 Do Until Loop
52 Do Loop while 53 Exit Do 54
While Wend 55 For Next 56 Select
62 Variables Naming Restrictions
74 Types Numbers 70 72 Date 72 String
75 Const 77 String Functions -
100 Len Left Right Mid InStr Split Rnd Random
Write a Comment
User Comments (0)
About PowerShow.com