Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[WIP] 99 Bottles of Beer v2.0

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> Internet Programming
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jun 26th, 2007, 4:00am    Post subject: [WIP] 99 Bottles of Beer v2.0 Reply with quote

Hello all,

I'm considering posting an update to the Run BASIC snippet I submitted to www.99-bottles-of-beer.net that uses the new and more advanced features of RB. Because RB is so early in its development, I'll probably put off submitting this until I'm pretty sure a feature is stable. Also, if any of you have suggestions on ways to improve on this version, I'm willing to bend.

Please excuse the lack of comments for the time being. I will add some later.

Code:
CSSID #scroll, "{
  border: 1px solid;
  font: 10pt sans-serif;
  height: 25em;
  overflow: auto;
  padding: 4pt;
}"

CSSClass "#scroll P", "{
  margin: 4pt;
}"

OnTheWall$ = " on the wall"

Div scroll
  For beer = 99 To 1 Step -1
    HTML "<P>"
      Print HowManyBottles$(beer);OnTheWall$;". ";
      Print HowManyBottles$(beer);"."

      Print "Take one down and pass it around. ";
      Print HowManyBottles$(beer-1);OnTheWall$;".";
    HTML "</P>"
  Next

  HTML "<P>"
    Print HowManyBottles$(0);OnTheWall$;". ";
    Print HowManyBottles$(0);"."

    Print "Go to the store and buy some more. ";
    Print HowManyBottles$(99);OnTheWall$;"."
  HTML "</P>"
End Div

End

Function HowManyBottles$( Num )
  bottles$ = Word$(" bottle | bottles ", 1 + (Num <> 1), "|")
  If Num Then
    howmany$ = InitCaps$(EnNumber$(Num))
  Else
    howmany$ = "No more"
  End If
  HowManyBottles$ = howmany$ + bottles$ + " of beer"
End Function

Function EnNumber$( Num )
  ones = Num mod 10
  tens = (Num - ones) / 10
  Select Case tens
    Case 0 ' do nothing; Num < 10
    Case 1 ' teens: 10 <= Num <= 19
      If ones < 3 Then
        tens$ = Word$("ten eleven twelve", ones + 1)
      Else
        tens$ = Word$("thir four fif six seven eigh nine", ones - 2) + "teen"
      End If
      ' Teens eat everything.
      ones = 0
    Case Else ' tees
      tens$ = Word$("twen thir for fif six seven eigh nine", tens - 1) + "ty"
  End Select

  ones$ = Word$("one two three four five six seven eight nine", ones)

  If Len(tens$) * Len(ones$) Then dash$ = "-"

  EnNumber$ = tens$ + dash$ + ones$
End Function

Function InitCaps$( Text$ )
  InitCaps$ = Upper$(Left$(Text$, 1)) + Mid$(Text$, 2)
End Function

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> Internet Programming All times are GMT
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group