Language VBScript
(correct lyrics version)
Date: | 07/19/05 |
Author: | exec |
URL: | n/a |
Comments: | 8 |
Info: | n/a |
Score: | ![]() |
'99 Bottles of Beer in VBS 'coded by exec For i = 99 To 0 Step -1 Select Case i Case 1 msg i & " Bottle of beer on the wall, " & i & " bottle of beer." msg "Take one down and pass it around, no more bottles of beer on the wall." Case 0 msg "No more bottle of beer on the wall. No more bottles of beer..." msg "Go to the store and buy some more... 99 bottles of beer." Case Else msg i & " Bottles of beer on the wall, " & i & " bottles of beer." msg "Take one down and pass it around, " & i - 1 & " bottles of beer on the wall." End Select Next Sub msg(message) MsgBox message, , "99 Bottles of Beer" End Sub
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
WSH using recursion and Microsoft Agent | Bob Stammers | 03/10/06 | 1 | ![]() ![]() |
Demonstrates use of "class" | Bruce M. Axtens | 09/29/05 | 0 | ![]() ![]() |
WSF, Microsoft Agent, EN/FR/DE | Bob Stammers | 06/02/06 | 1 | ![]() ![]() |
long version | Jonathan Harrison | 05/17/05 | 3 | ![]() ![]() |
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
what else then msgboxes would you use?
You could also stream the lyrics into a textfile then display using notepad.
But at that time I don't knew another Method^^"
When you get to i=2 your i - 1 & " bottles of beer on the wall." is still plural: 1 bottles of beer on the wall."
set args = wscript.arguments
if args.count < 1 then
wscript.echo "Usage: cscript 99bob.vbs [number_of_beers]" & vbCrLf
wscript.quit(1)
end if
Set oBeer = New Beer
numBeer = args(0)
oBeer.Sing(numBeer)
class Beer
Private Sub Class_Initialize()
'constructor
End Sub
Public Function Sing(byval value)
For i = value To 0 Step -1
Select Case i
Case 2
verse = "2 bottles of beer on the wall, 2 bottles of beer." & vbCrLf &_
"Take one down and pass it around, 1 bottle of beer on the wall." & vbCrLf
Case 1
verse = "1 bottle of beer on the wall, 1 bottle of beer." & vbCrLf &_
"Take one down and pass it around, no more bottle of beer on the wall." & vbCrLf
Case 0
verse = "No more bottle of beer on the wall. No more bottle of beer..." & vbCrLf &_
"Go to the store and buy some more... 99 bottles of beer." & vbCrLf
Case Else
verse = i & " Bottles of beer on the wall, " & i & " bottles of beer." & vbCrLf &_
"Take one down and pass it around, " & i - 1 & " bottles of beer on the wall." & vbCrLf
End Select
wscript.echo verse
Next
End Function
Private Sub Class_Terminate()
'destructor
End Sub
End Class
'99 Bottles of Beer in VBS
'coded by exec
'improved by moi, but still not great ...
For i = 5 To 3 Step -1 'substitute 99 to 3 for the whole deal
MsgBox i & " Bottles of beer on the wall, " & i & " bottles of beer."
MsgBox "Take one down and pass it around, " & i - 1 & " bottles of beer on the wall."
Next
MsgBox "2 Bottles of beer on the wall, 2 bottles of beer."
MsgBox "Take one down and pass it around, 1 bottle of beer on the wall."
MsgBox "1 Bottle of beer on the wall, 1 bottle of beer."
MsgBox "Take one down and pass it around, no more bottles of beer on the wall."
MsgBox "No more bottles of beer on the wall. No more bottles of beer..."
MsgBox "Go to the store and buy some more... 99 bottles of beer."
"This is not a "shortest code" contest"
"Your example should demonstrate the main advantages and features of the language"
Of course there were flaws in my code, but that was 4,5 years ago^^
Thanks to you all anyway.