Qbasicnews.com
November 20, 2019, 11:23:24 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: A musical note from QuickBASIC with XP?  (Read 6528 times)
Ralph
Ancient Guru
****
Posts: 544


« on: January 01, 2007, 07:33:37 PM »

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
                   
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
« Reply #1 on: January 01, 2007, 10:25:58 PM »

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...
Logged

/post]
Ralph
Ancient Guru
****
Posts: 544


« Reply #2 on: January 02, 2007, 12:17:39 AM »

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?
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
« Reply #3 on: January 02, 2007, 09:51:17 AM »

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$=""
Logged

/post]
Ralph
Ancient Guru
****
Posts: 544


« Reply #4 on: January 02, 2007, 12:46:26 PM »

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?
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Skyler
Ancient Guru
****
Posts: 564



« Reply #5 on: January 02, 2007, 04:08:22 PM »

I'm not a professional, but I shun DO-LOOP for no reason whatsoever. Just plain old personal preference.
Logged

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
Ralph
Ancient Guru
****
Posts: 544


« Reply #6 on: January 02, 2007, 04:31:19 PM »

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(R) GW-BASIC(TM) 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?
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Skyler
Ancient Guru
****
Posts: 564



« Reply #7 on: January 02, 2007, 06:13:21 PM »

Comment!

It supports Do-Loop but has no error for do without loop?  Shocked
Logged

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
Ralph
Ancient Guru
****
Posts: 544


« Reply #8 on: January 02, 2007, 06:30:52 PM »

Skyler wrote:

Quote from: "Skyler"
Comment!

It supports Do-Loop but has no error for do without loop?  Shocked

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.
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Skyler
Ancient Guru
****
Posts: 564



« Reply #9 on: January 02, 2007, 08:40:29 PM »

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!
Logged

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
Ralph
Ancient Guru
****
Posts: 544


« Reply #10 on: January 02, 2007, 09:36:07 PM »

Yes, Tyler, a professional has to keep up with the latest developements, he has to remain on, or near, the cutting edge of programming.  We mere amateurs simply keep on using the same old programs we started and learned with, unless we are compelled to use and learn newer ones, as happens when we are employed by progressive firms.

I'm not saying that there aren't professionals out there who still are able to live, using the old programs, but, the great majority will be using much more advanced programs, that allow very powerful results!  

To us, trying to keep up with the newer programs would be so time and money consuming, that we just stay put!  After all, we really don't have to go through all that pain and trouble, only to have to buy and learn yet another new program or language, time after time!  But, a professional is in that situation very frequently, and knows that he just has to be on the ball with most every new thing that hits the market, or lose out.
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #11 on: January 04, 2007, 01:55:52 AM »

Just fyi, I did some testing when I used QB. I made a simple test that ran a FOR...NEXT against DO...LOOP. FOR...NEXT won the match. I never did test WHILE...WEND though. Wink
Logged
Ralph
Ancient Guru
****
Posts: 544


« Reply #12 on: January 04, 2007, 02:28:28 AM »

Hey, Dr, why not test the While/Wend now?  And, what was your test all about?  What did you prove?
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Dr_Davenstein
Na_th_an
*****
Posts: 2052


« Reply #13 on: January 04, 2007, 02:34:24 AM »

Oh... Well, I don't have QB anymore, so I can't test it now. The original test was a speed comparison though. Wink
Logged
Skyler
Ancient Guru
****
Posts: 564



« Reply #14 on: January 04, 2007, 11:47:40 AM »

I forget what the statement is to get the no of milliseconds after midnight, but you would do something like this:

Code:

   oldtime$ = no_of_milliseconds$
   for x = 1 to 100: next x
   newtime$ = no_of_milliseconds$
   print "FOR-NEXT took "; newtime$; " milliseconds."


Then repeat for Do-Loop and While-Wend.
Logged

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
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!