Language VBA
Date: | 04/20/05 |
Author: | Philipp Winterberg |
URL: | http://www.winterbergs.de/ |
Comments: | 2 |
Info: | n/a |
Score: | (2.38 in 34 votes) |
' VBA/Access version of 99 Bottles of beer (Bottles.mdb) ' Philipp Winterberg, http://www.winterbergs.de ' ' How to use: ' 1. Create a new database (Bottles.mdb) ' 2. Create a new module ' 3. Paste this code snippet ' 4. Click "Play"-button and enjoy ;) ' Public Function Bottles() On Error GoTo Bottles_Err Dim b As Integer For b = 99 To 1 Step -1 If MsgBox(b & " bottle(s) of beer on the wall, " & vbCr & b & " bottle(s) of beer." & vbCr & _ "Take one down, pass it around, " & vbCr & (b - 1) & " bottle(s) of beer on the wall.", _ 65, "99 Bottles of Beer") = 2 Then Exit Function End If Next Bottles_Exit: Exit Function Bottles_Err: MsgBox Error$ Resume Bottles_Exit End Function
Download Source | Write Comment
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
James R. Mireles said on 08/17/06 17:03:33
# Great sample!
# Modify to properly pluralize bottle ("bottles" or "bottle", rather than
# "bottle(s)", and also to end with "No bottles of beer on the wall."
Dim bBefore As Integer
Dim bAfter As Integer
For bBefore = 99 To 1 Step -1
bAfter = bBefore - 1
If MsgBox(bBefore & " bottle" & IIf(bBefore = 1, "", "s" & " of beer on the wall, " & vbCr & _
bBefore & " bottle" & IIf(bBefore = 1, "", "s" & " of beer." & vbCr & _
"Take one down, pass it around, " & vbCr & IIf(bAfter = 0, "No", bAfter) & " bottle" & IIf(bAfter = 1, "", "s" & " of beer on the wall.", _
65, "99 Bottles of Beer" = 2 Then
Exit Function
End If
Next
# Regards,
# James R. Mireles
# Houston, TX
barrym said on 03/29/10 08:54:02
More lazy-ass "bottle(s)" code. C'mon Phil, give us a conditional
expression or two. Geez Louise..........