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

Galileo

• Jr. Member
• Posts: 91
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/2018sub 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 subfor 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: 241
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 FunctionFunction 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 / nVidia GTX 1060Ti, 6GB VRAM / x64 Win 7 Ult.)

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.sbivoice = 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.")NEXTCOM::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 »