Converting To VB6 from MS Professional Basic 7.1 or QBX


There were some rather nice capabilities in PB7.1 that don't seem to exist in VB6.

I've managed to find a way to deal with PB's "INKEY$", so one of my problems has vanished.

But does anyone know of a nice way of converting PB's "PLAY()" either to code that will work in VB6 or to, say, a .wav file?

PZI

If you enjoyed this post, subscribe for updates (it's free)

Not familiar with PB

Hi - I'm not familiar with PB can you explain what the PLAY() function does? Does it play a .wav file? I might be able to help once a know what you're trying to do.

Description of PLAY() command

Here you go!

Octave command
on                     Sets the current octave. There are seven octaves, numbered 0-6
>                        Increases octave by 1. Octave cannot go beyond 6
>                        Decreases octave by 1. Octave cannot drop below 0
 
Tone command
A-G                     Plays a note in the range A-G. The number sign (#) or the plus sign (+) after a note specifies sharp; a minus sign (-) specifies flat. Not
                              case sensitive.
Nn                        Plays note n. The range for n is 0-84 (in the seven possible octaves there are 84 notes); an n value of 0 means a rest.
 
Duration command
Ln                        Sets the length of each note. L4 is a quarter note, L1 is a whole note, etc. The range for n is 1-64. The length can also follow the
                           note when a change of length only is desired for a particular note. For example A16 can be equivalent to L16A.
MN                     Sets "music normal" so that each note will play 7/8 of the time determined by the length (L).
ML                       Sets "music legato" so that each note will play the full period set by length (L).
MS                        Sets "music staccato" so that each note will play 3/4 of the time determined by the length (L).
 
Tempo command
Pn                           Specifies a pause, ranging from 1 to 64. This option corresponds to the length of each note, set with Ln.
Tn                           Sets the "tempo", or the number of L4 quarter notes in one minute. The range for n is 32-255. The default for n is 120
                              Because of the slow clock-interrupt rate, some notes will not play at higher tempos (L64 at T255, for example).
 
Mode command
MF or mf                Sets music (PLAY statement) and SOUND to run in the foreground. That is, each subsequent note or sound will not start
                              until the previous note or sound has finished. This is the default setting.
MB or mb               Music (PLAY statement) and SOUND are set to run in the background. That is, each note or sound is placed in a buffer,
                              allowing the BASIC program to continue executing while the note or sound plays in the background. The maximum number
                              of notes that can be played in the background at one time is 32.
 
Suffix
+ or #                     Follows a specified note and turns it into a sharp.
-                              Follows a specified note and turns it into a flat.
.                              A period after a note causes the note to play one-and-a-half times the length determined by L times T. The period has the
                              same meaning as in a musical score. Multiple periods can appear after a note. Each period adds a length equal to one half
                              the length of the previous period. For example, the command A. plays 1 + 1/2, or 3/2 times the length. A . . plays 1 + 1/2 + 1/4 or 7/4 times the
                              length. Periods can appear after a pause (P). In this case, the pause length is scaled in the same way notes are scaled.
 
Substring command
"X" + VARPTR$(*string*)
                           Executes a substring. This powerful command enables you to execute a second substring from a string. You can have one string
                           expression execute another, which executes a third, and so on.

I think we can ignore the Substring command, but it would certainly be nice if there were a way of going from PLAY("mbL48MLo0g+gg-fee-dd-L8c") to a .wav file that was a quick glissando from G# down to a then-prolonged C. It would probably be easy to do in an Apple, but I really need to have the .wav files so I can hook 'em into a program running in Visual Basic.

Play a sound using direct x

Here is a tutorial that uses Direct X to play a sound:
DirectX sound tutorial
Is that what you wish to do? Or do you want to play a .wav file that is already recorded? If you simply want to play a .wav file there is a windows API to do that - I can find it if you need it. Let me know.

No, not quite

Let's grab that stick by the other end.

*If* I had a .wav file, you could (and, I'm sure, would) help me figure out how to play in in VB6.

The problem is that in PB7 I didn't need a .wav file. I simply wrote a command PLAY(*string*), where *string* was constructed according to the rules for the special language, as I described, and PB7 generated the requisite code to implement the PLAY command from the *string*.

I have a PB7 program that I'm converting to VB6. There doesn't appear to be an obvious way of implementing, in VB6, the PB7 PLAY command. Hence my original query ... was there, in dim-and-distant past, some program that did this? Or, more likely, can you see a way of converting the *string*s that I now have (in PB7) so that they will make suitable noises in VB6?

PZI

I Understand Now

OK, I see what you are saying now. I don't know of any program that lets you simply put in the *string* and save it as a .wav file. This might help you - there is a windows API call that plays a sound of the specified frequency for the specified duration. Here is the code that demonstrates it.
Option Explicit

Private Declare Function Beep Lib "kernel32.dll" ( _
    ByVal dwFreq As Long, _
    ByVal dwDuration As Long) As Long

Private Sub Command1_Click()
    Beep 5000, 100
End Sub
Now if you look up what the frequency is for your different notes you should be able to write your own PLAY function.

Eureka

Well, I shan't run naked through the streets ... the neighbors might not understand ... but I think that solves my problem very nicely. With a bit of grunting and straining I believe I can, indeed, write a small transmogrifier from the subset of the MusicMacroLanguage that I'm using to a string of Beeps!

Might even make sense to package it for re-use by me as well as others!

PZI

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.