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 Sax Basic

Date:02/17/10
Author:Markus Welz
URL:n/a
Comments:1
Info:http://www.ftgsoftware.com/manuals/basic32.pdf
Score: (2.93 in 14 votes)
Option Explicit

'This script writes the song "99 Bottles of Beer" to the Immediate window of the code editor.
Sub Main
  Dim i As Long

  'Clear previous output. This function is probably the only difference to VBA ;-)
  Debug.Clear

  For i = 99 To 0 Step -1

    Select Case i
      Case 2
        Debug.Print i & " bottles of beer on the wall, " & i & " bottles of beer."
        'Special case singular.
        Debug.Print "Take one down and pass it around, " & i-1 & " bottle of beer on the wall."
      Case 1
        'Special case singular.
        Debug.Print i & " bottle of beer on the wall, " & i & " bottle of beer."
        'Special case zero.
        Debug.Print "Take one down and pass it around, no more bottles of beer on the wall."
      Case 0
        'Special case zero.
        Debug.Print "No more bottles of beer on the wall, no more bottles of beer."
        Debug.Print "Go to the store and buy some more, 99 bottles of beer on the wall."
      Case Else
        'Common case.
        Debug.Print i & " bottles of beer on the wall, " & i & " bottles of beer."
        Debug.Print "Take one down and pass it around, " & i-1 & " bottles of beer on the wall."
    End Select

    'An empty line.
    Debug.Print ""

  Next i

End Sub

Download Source | Write Comment

Alternative Versions

Comments

>>  barrym said on 07/16/10 05:52:55

barrym Regarding cases 2 and 1: Since the value of i is already known, wouldn't it be
more efficient to eliminate the references to it and put the "2" and "1" inside
the string literals?

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: