Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

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: (2.88 in 8 votes)
'~ "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

VersionAuthorDateCommentsRate
correct lyrics versionexec07/19/058
WSH using recursion and Microsoft AgentBob Stammers03/10/061
WSF, Microsoft Agent, EN/FR/DEBob Stammers06/02/061
long versionJonathan Harrison05/17/053
short versionPhilipp Winterberg04/20/050

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: