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

Galileo

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
99 bottles of beer
« on: 27. June 2018, 21:51:30 »
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

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Re: 99 bottles of beer
« Reply #1 on: 28. June 2018, 01:41:08 »
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.
Mike
____________________________________________________________________________________________
(3.6GHz i5-3470, 16GB RAM / 2 x nVidia GTX 650Ti SLI-bridged, 2GB VRAM / x64 Win 7, x86 elementaryOS Luna)

ScriptBasic

  • Guest
Re: 99 bottles of beer
« Reply #2 on: 28. June 2018, 04:29:28 »
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: 28. June 2018, 07:57:20 by John »