Brent Site Admin
Joined: 01 Jul 2005 Posts: 792
|
Posted: Jun 26th, 2007, 4:00am Post subject: [WIP] 99 Bottles of Beer v2.0 |
|
|
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 |
|