|
-
Oct 25th, 2011, 08:54 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Use of variables in Activex8 sound API to set Constants.
I am trying to write code using the ActiveX8 reference to generate short bursts of sound through my speaker at a FREQ(in Hz) and for a dur(ation) (in secs.). Parameters are specified at Option Explicit as constants.
The routine works 100% if I write code which specifies these parameters : eg.
Const FREQ = 500 'means 500 Hz
Const dur = 0.2 'means 200 milliseconds
So far, so good. But now I wish to have the VB6 program vary these parameters. For example, I would like to dim an integer variable named MYFREQ and be able to write Const FREQ = MYFREQ. However this fails. I get the error message "Assignment to Constant not permitted".
How can I reset, in software, the value of an API Const to the instantaneous value of a variable? Does the variable need to be Dim'd as a special type? How to assign a new value to a Constant in software?
Suggestions gratefully requested.
camoore
Wales
UK
Last edited by camoore; Oct 25th, 2011 at 09:03 AM.
Reason: some more info added.
-
Oct 25th, 2011, 10:10 AM
#2
Re: Use of variables in Activex8 sound API to set Constants.
a CONST declaration simply means it doesn't change, ever.
In your routine that plays the sounds, pass the desired frequency & duration as variables that default to 500 & .02 respectively. Maybe something like this...
Code:
Public Sub PlayTheSound(Optional ByVal Frequency As Long, Optional ByVal Duration as Double) ' or should Double be Single?
CONST FREQ = 500
CONST dur = 0.2
If Frequency = 0 The Frequency = FREQ
If Duration = 0 then Duration = dur
' now use Frequency & Duration variables instead of the constants
End Sub
-
Oct 25th, 2011, 06:12 PM
#3
Thread Starter
Hyperactive Member
Re: Use of variables in Activex8 sound API to set Constants.
Thank you, La Volpe, for your suggestions. I have just started to try to understand ActiveX8 and its applications to the import and export of sound. At first sight, it is a very complex affair - but lots of things are thus at first encounter. Thanks to your suggestions, I have managed to get over the limitations apparently imposed by the use of Const declarations.
I have many more queries about VB6 interfacing with audio via ActiveX8, but these must be a learning curve for me and not an ever-extending thread here.
I found this forum thread, which is a tutorial about VB6 - audio interfacing bothways. At first reading, it seems most comprehensive but somewhat "over my head". However I mention it below in case it might be of assistance to other members reading this thread.
http://www.vbforums.com/showthread.php?t=388562
I shall mark this thread of mine as resolved, and thanks again for your prompt reply.
camoore
Wales
UK
Last edited by camoore; Oct 25th, 2011 at 06:16 PM.
-
Oct 25th, 2011, 08:34 PM
#4
Re: [RESOLVED] Use of variables in Activex8 sound API to set Constants.
-
Oct 26th, 2011, 04:49 AM
#5
Thread Starter
Hyperactive Member
Re: [RESOLVED] Use of variables in Activex8 sound API to set Constants.
Yes, my apologies for the incorrect reference. That goes to show how new I am to this audio interfacing aspect of VB6 (and to many other aspects of it!).
My application is to write an automated morse code sender. which is now going along OK. Subsequently I wish to try to write an automated morse decoder - which will obviously involve the import rather than the export of audio signals.
camoore
Wales
UK
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|