Author Topic: 99 bottles of beer  (Read 1592 times)

Galileo

  • Guest
99 bottles of beer
« on: June 27, 2018, 07:51:30 PM »
I love simple code:

Code: [Select]
// Rosetta Code problem: http://rosettacode.org/wiki/99_Bottles_of_Beer
// Adapted from Io to Yabasic by Galileo, 06/2018

sub bottle$(i)
    if i=0 return "no more bottles of beer"
    if i=1 return "1 bottle of beer"
    return str$(i) + " bottles of beer"
end sub

for i = 99 to 1 step -1
    print bottle$(i), " on the wall, \n", bottle$(i), "\n", "take one down, pass it around,\n", bottle$(i - 1), " on the wall.\n"
next

Mike Lobanovsky

  • Guest
Re: 99 bottles of beer
« Reply #1 on: June 27, 2018, 11:41:08 PM »
In a hooked/subclassed MessageBox:

Code: [Select]
' ===============================
' 99 Bottles of Beer GUI Version
' ©2011 Mike LOBKO-LOBANOVSKY
' ===============================

#Option Strict
#EscapeChars On

#Include <Include/Windows.inc>

#Define Bottles :
#Define Alcohol Integer
#Define Some_Beer_Left Beer

' ============= LOL ============
Dim Beer As Alcohol = 99 Bottles
' ==============================

SetWindowsHookEx(WH_CBT, AddressOf CBTProc, NULL, GetCurrentThreadId())
MsgBox(NULL, LPad("\n", 128) & LPad, "99 Bottles of Beer in a Fancy FBSL v3 Message Box GUI :)", MB_OK BOr MB_ICONINFORMATION)
UnhookWindowsHookEx(SetWindowsHookEx)

Function CBTProc(ByVal %ncode, ByVal %wparam, ByVal %lparam) As Integer
If ncode >= 0 Then
If ncode = HCBT_ACTIVATE Then
SetWindowLong(wparam, GWL_WNDPROC, AddressOf MsgBoxProc)
SetTimer(wparam, 1000, 100, NULL)
Return 0
End If
End If
Return CallNextHookEx(SetWindowsHookEx, ncode, wparam, lparam)
End Function

Function MsgBoxProc(ByVal %hwnd, ByVal %msg, ByVal wparam, ByVal lparam) As Integer
Static buffer As String * 256
Select Case msg
Case WM_TIMER
If wparam = SetTimer Then
If Some_Beer_Left Then
SPrintF(buffer, "%d bottle%s of beer on the wall, %d bottle%s of beer...\nTake one down and pass it around -- %d bottle%s of beer!", _
%Beer, $IIf(Beer = 1, "", "s"), %Beer, $IIf, %Decr(Beer), $IIf(Beer = 1, "", "s"))
Else
SPrintF(buffer, "No more bottles of beer on the wall, no more bottles of beer...\nGo to the store and buy some more ninety nine bottles of beer!")
End If
FbslSetText(GetDlgItem(hwnd, &HFFFF), Left(buffer, SPrintF))
Return 0
End If
Case WM_CLOSE
KillTimer(hwnd, SetTimer)
SetWindowLong(hwnd, GWL_WNDPROC, SetWindowLong)
End Select
Return CallWindowProc(SetWindowLong, hwnd, msg, wparam, lparam)
End Function

The zip below contains a precompiled executable.

ScriptBasic

  • Guest
Re: 99 bottles of beer
« Reply #2 on: June 28, 2018, 02:29:28 AM »
How about a SAPI version of 99 Bottles of Beer?

Quote
I love simple code:
Me too!

Code: [Select]
IMPORT COM.sbi

voice = COM::CREATE(:SET, "SAPI.SpVoice")
FOR beers = 99 to 1 STEP -1
  IF beers = 1 THEN
    beers_str = "1 bottle of beer"
  ELSE
    beers_str = beers & " bottles of beer"
  END IF
  COM::CBN(voice, "speak", :CALL, beers_str & " on the wall. Take one down, pass it around.")
NEXT
COM::RELEASE(voice)

This forum doesn't allow attaching .mp3 files so I had to zip it.  :-\
« Last Edit: June 28, 2018, 05:57:20 AM by John »