Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » API

Post new topic   Reply to topic
sndSoundPlay
View previous topic :: View next topic  
Author Message
wezel
Freshman


Joined: 09 Oct 2003
Posts: 30

PostPosted: Oct 10th, 2003 01:05 PM    Post subject: sndSoundPlay Reply with quote

Hi,
I've got an API function in my app but it's not working...
Here's the code:

Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal strFile As String, lngPlayFile As Long) As Long

'To play sound:

sndPlaySound App.Path & "sound.wav", 1

I've used this API function before but i'm not sure if i wrote it this way...
Does anyone knows how to make this API function work ?
Thanx at advance
Wesley
_________________
Real Programmers don't comment their code - it's hard to write, it should be hard to read
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wezel
Freshman


Joined: 09 Oct 2003
Posts: 30

PostPosted: Oct 10th, 2003 01:38 PM    Post subject: Reply with quote

oops, forfor a Byval there in the API Declaration... Works now
/me slaps wezel
_________________
Real Programmers don't comment their code - it's hard to write, it should be hard to read
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Oct 11th, 2003 01:43 AM    Post subject: Reply with quote

For a better description and example check this [api]sndPlaySound[/api]
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
wezel
Freshman


Joined: 09 Oct 2003
Posts: 30

PostPosted: Oct 12th, 2003 05:56 PM    Post subject: Reply with quote

Thanx Avis.
But the thing is... I don't like using code I don't understand myself. And I don't understand these parts of the code:

Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2

sndPlaySound CDBox.filename, SND_ASYNC Or SND_NODEFAULT

What does the value that the sonstants get mean ?

Why do you have to use constants ?

Thanx
Wesley
_________________
Real Programmers don't comment their code - it's hard to write, it should be hard to read
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Oct 13th, 2003 07:01 AM    Post subject: Reply with quote

Well constants are used to describe a value, a number so it can be easier to read and recognize. For example, isn't easier to read this :

Code:
sndPlaySound CDBox.filename, SND_ASYNC Or SND_NODEFAULT


than this?

Code:
sndPlaySound CDBox.filename, &H1 Or &H2


Even though both are correct...
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
wezel
Freshman


Joined: 09 Oct 2003
Posts: 30

PostPosted: Oct 13th, 2003 07:12 AM    Post subject: Reply with quote

Yeah, that's true, but why do they get that value ?
And why do the the names of the constants have to be words like SND_ASYNC ?
I know I have a lot of questions, but, if you'd be so kind to explain me this I would be very gratefull, I've been asking myself this question for quite some time now
Thanx!
Wesley
_________________
Real Programmers don't comment their code - it's hard to write, it should be hard to read
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Oct 13th, 2003 11:55 AM    Post subject: Reply with quote

Well the name is something like that so that it can be generally recognized. You can name a constant anything you like! You can change SND_ASYNC to Wezel and put Wezel in your code instead of SND_ASYNC and it'll work. A constant is just something that has a value and can't change. Of course, if everyone renamed the constants to anything that they wanted no one else would understand the code Wink
They get that value for no particular reason! It is just that the API when it was designed it knew how to recognize some numbers and do things accordingly. So whoever made the API also made a list with the capabilities of the API (and the numbers that it reads) and can do something afterwards. So I guess the constant names come from the creator of the API (that uses them) creator...

HTH,
Philip
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
wezel
Freshman


Joined: 09 Oct 2003
Posts: 30

PostPosted: Oct 13th, 2003 12:00 PM    Post subject: Reply with quote

Thanx!
Now I can use more API's I wanted to use before but didn't understand!
Thanx!
Wesley
_________________
Real Programmers don't comment their code - it's hard to write, it should be hard to read
Back to top
View user's profile Send private message Send e-mail Visit poster's website
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Oct 13th, 2003 12:28 PM    Post subject: Reply with quote

No problem Wink

Also it might be a good idea to download the API-Guide and the API Viewer Wink
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » API All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic