Language VBScript
(Demonstrates use of "class")
| Date: | 09/29/05 |
| Author: | Bruce M. Axtens |
| URL: | http://codeaholic.blogspot.com |
| Comments: | 0 |
| Info: | n/a |
| Score: |
'~ "Object-Oriented" 99Bob in VBScript.
'~ Bruce M. Axtens, 2005-09-29.
'~ http://codeaholic.blogspot.com
'2nd version. Wanting to say "one" or "it" complicated matters a bit.
option explicit
class wall
private numBottles
private sub class_initialize()
numBottles = 99
end sub
public function Count()
Count = numBottles
end function
public sub takeOneDown()
numBottles = numBottles - 1
end sub
public function bottlesOfBeer()
bottlesOfBeer = plurals( numBottles ) & " of beer"
end function
private function plurals( num )
if num > 1 then
plurals = num & " bottles"
elseif num = 1 then
plurals = num & " bottle"
else
plurals = "No more bottles"
end if
end function
public sub refill()
numBottles = 99
end sub
public function pronoun()
if numBottles > 1 then
pronoun = "one"
else
pronoun = "it"
end if
end function
end class
dim myWall
set myWall = new wall
dim timesThrough
const MAX_TIMES_THROUGH = 1
timesThrough = 0
do
wscript.echo myWall.bottlesOfBeer() & " on the wall."
wscript.echo myWall.bottlesOfBeer() & "."
if myWall.Count = 0 then
wscript.echo "Go to the store and buy some more."
myWall.refill
timesThrough = timesThrough + 1
else
wscript.echo "Take " & myWall.pronoun() & " down and pass it round."
myWall.takeOneDown
end if
wscript.echo myWall.bottlesOfBeer() & " on the wall."
wscript.echo
if timesThrough >= MAX_TIMES_THROUGH then
exit do
end if
loop
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| correct lyrics version | exec | 07/19/05 | 8 | |
| long version | Jonathan Harrison | 05/17/05 | 3 | |
| WSH using recursion and Microsoft Agent | Bob Stammers | 03/10/06 | 1 | |
| WSF, Microsoft Agent, EN/FR/DE | Bob Stammers | 06/02/06 | 1 | |
| short version | Philipp Winterberg | 04/20/05 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments