Bob Baddeley
Nov 3rd, 1999, 11:26 AM
A lot of people have been wondering how to make a sound in VB like QBasic does. I found a pseudo-solution. It is kind of cheating, but maybe somebody could look at this and improve on it.
I wanted a scrollbar that as you slide, it makes a different frequency. In QBasic 7.1 I wrote a program that looks like this:
Open "c:\freq.bob" For Random As #1
Get #1, 1, A%
SOUND A%, 5
Close #1
SLEEP 1
and made it into an .EXE using that awesome feature of QBasic 7.1. Then I wrote another QBasic program that went like:
SOUND 37, 0
and made it into a program as well. Finally, I went to VB and put a scroll bar on a form. The scroll bar has to have values between 37 and 32,767. Then put in the code:
Private Sub Form_Unload(Cancel As Integer)
BOBSTOP = Shell("C:\freqstop.exe", vbHide)
End Sub
Private Sub HScroll1_Change()
Open "C:\freq.bob" For Random As #1
Put #1, 1, HScroll1.Value
Close #1
BOB = Shell("C:\freq.exe", vbHide)
End Sub
This allows you to move the bar to set the frequency. The bar value goes to a file (freq.bob) that the QBasic program reads to get the frequency. It's kind of clunky because it isn't a smooth slide, but it accomplishes the purpose. The freqstop.exe is pretty important because for some reason the sound won't stop playing until you run it. Oh well. If you have any suggestions for improvement, or need help getting this to run, or can't make the .EXEs in QB 7.1, don't hesitate to email or post. :)
I wanted a scrollbar that as you slide, it makes a different frequency. In QBasic 7.1 I wrote a program that looks like this:
Open "c:\freq.bob" For Random As #1
Get #1, 1, A%
SOUND A%, 5
Close #1
SLEEP 1
and made it into an .EXE using that awesome feature of QBasic 7.1. Then I wrote another QBasic program that went like:
SOUND 37, 0
and made it into a program as well. Finally, I went to VB and put a scroll bar on a form. The scroll bar has to have values between 37 and 32,767. Then put in the code:
Private Sub Form_Unload(Cancel As Integer)
BOBSTOP = Shell("C:\freqstop.exe", vbHide)
End Sub
Private Sub HScroll1_Change()
Open "C:\freq.bob" For Random As #1
Put #1, 1, HScroll1.Value
Close #1
BOB = Shell("C:\freq.exe", vbHide)
End Sub
This allows you to move the bar to set the frequency. The bar value goes to a file (freq.bob) that the QBasic program reads to get the frequency. It's kind of clunky because it isn't a smooth slide, but it accomplishes the purpose. The freqstop.exe is pretty important because for some reason the sound won't stop playing until you run it. Oh well. If you have any suggestions for improvement, or need help getting this to run, or can't make the .EXEs in QB 7.1, don't hesitate to email or post. :)