Results 1 to 5 of 5

Thread: [RESOLVED] Use of variables in Activex8 sound API to set Constants.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    403

    Resolved [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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    403

    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.

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] Use of variables in Activex8 sound API to set Constants.

    Oh you mean DirectX 8.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2006
    Posts
    403

    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
  •  



Click Here to Expand Forum to Full Width