Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A musical note from QuickBASIC with XP?
#1
Anybody have any answers?

Code:
'1NOTE.BAS, by Ralph A. Esquivel, 01/01/2007
'Have I discovered something strange and useful?

'I ran across this crazy thing, that, after 16 SLEEPs, my previously silent
'program suddenly communicates one, normal-sounding musical note to my
'loudspeakers, every time I press any key!

'Any clue as to what is going on?  Can this lead to being able to use sound
'with other than this one note?  Why would the SLEEP commnand, after 16
'repetitions, produce a note?


FOR i = 1 TO 30
    SLEEP
NEXT i
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#2
If I'm not mistaken the computer has a fixed size buffer where keyboard input (from keys with an ascii value) is stored. If you press a key (which has an ascii value) andd the buffer is full, the computer will beep.
The thing is that functions like INKEY$ will retrieve the first entry in the buffer and then delete it from the buffer, while SLEEP will not.
The result is that in the endless sleep loop you will fill the buffer with each keystroke but never empty it...
/post]
Reply
#3
red_Marvin:

Ahhhhh! Of course, now that you point it out and explain it all! Thank you! Too bad it didn't turn out that one could get different kinds of notes out of QuickBASIC 4.5 and Windows XP! Sad

Do you know if SLEEP is the only statement to do this? And, how would I flush out the buffer to get rid of the "over 15" warning sound that SLEEP is producing?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#4
I'd guess any command that detects keyboard inpput (again, ascii stuff only afaik) while not emptying the buffer afterwards will produce a beeping sound, but to my knowledge it is SLEEP is the only one.
To avoid the beeping you could always empty the buffer after the SLEEP statement:
Code:
DO
SLEEP
foo$=INKEY$
LOOP
Or if waiting for a keypress is the important thing you could avoid using SLEEP:
Code:
DO
DO : LOOP WHILE INKEY$=""
DO : LOOP UNTIL INKEY$=""
/post]
Reply
#5
Just curious, but, why is the DO/LOOP seemingly preferred over the WHILE/WEND?

For instance, you would seem to use:
DO : LOOP WHILE INKEY$="", or, perhaps:
DO WHILE INKEY$="":LOOP

while I would prefer to use:
WHILE INKEY$="":WEND

Any reason why the WHILE/WEND seems to be shunned by the professionals?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#6
I'm not a professional, but I shun DO-LOOP for no reason whatsoever. Just plain old personal preference.
In the beginning, there is darkness – the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Reply
#7
Skyler:

I am like you! I believe that folk, such as you and I, first learned the WHILE/WEND and the FOR/NEXT methods of looping, and were able to accomplish most anything we needed, so, we never got around to use the DO/LOOPs that seem to be preferred by the professionals. I think we like to keep things simpler, and use "the good old stuff" that we understand so well! Right?

Edited a little later:
I explored "Microsoft® GW-BASIC™ Version 3.20" and found an error message for "FOR without NEXT", but no "DO without LOOP", which leads me to believe what I had thought earlier, that the DO/LOOP was a later addition to BASIC-based languages. Comments?
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#8
Comment!

It supports Do-Loop but has no error for do without loop? :o
In the beginning, there is darkness – the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Reply
#9
Skyler wrote:

Quote:Comment!

It supports Do-Loop but has no error for do without loop? :o
No, it doesn't support DO/LOOP! The fact that there was no error message for DO without LOOP was meant to mean just that. Just to prove it further, I entered the following in my GW-BASIC.exe:
Code:
10 DO
20    PRINT "HI"
30 LOOP
and entered RUN. It reported, "Syntax error in 10", and stopped there.

By the way, mine is Version 3.2, and the file is dated 3/1/1987.
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#10
Thank you for the clarification.

Since Do-Loop is newer, that would mean we've learned from older tuts. No wonder we're not professionals!
In the beginning, there is darkness – the emptiness of a matrix waiting for the light. Then a single photon flares into existence. Then another. Soon, thousands more. Optronic pathways connect, subroutines emerge from the chaos, and a holographic consciousness is born." -The Doctor
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)