Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relative file paths?

Status
Not open for further replies.

SerialCoder

Programmer
Oct 18, 2002
95
0
0
US
I am building my first program using VB6 Working model. I am using some sound files and was curious if I am able to reference them with a relative file pahs?

is this possible?
is this advisiable?
is this when packaged as and exe will it copy the files into the app?

regards,
dave
 
somethign = App.Path & "\mysound.wav"

hard-coded filenames suck! glad u asked coz its bad programing practice to use them! :) [Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
Code:
if (pop_tarts == 0)
{
   tantrum = 1;
}
[pc3]
 
it is possible using app.path, but when using this statement, the wav file(s) should be in the same directory or folders within the directory of your project.

is it advisable? it depends on what you want to do.

you should include the sound files while packaging it.
 
Of course you can look under a subfolder of ur app's folder by modifying the command to:
something = App.Path & "\Data\Sounds\asound.wav"

PraveenMenon's post is useful if you want the sounds packaged in the exe (so you only need to distribute the exe wihtout any other .wav files). I am unsure as to how to do this (i am relatively new to VB), so perhaps PraveenMenon or someone else can help with this. [Thanks in advance|Hope I helped you]
Exodus300
World-Wide Alliance of Evil and Twisted People
[red]"Experimentation by Example is the best learning tool" - Exodus300[/red]
Code:
if (pop_tarts == 0)
{
   tantrum = 1;
}
[pc3]
 
1) Use the VB Addin Manager to load the VB6 Resource Editor.
2) From the Tools menu, open Resource Editor
3) Include the wav files to the resource editor
4) Name the wav files accordingly and save the res file
5) use the following source to call them from your app

'==================================================================
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_MEMORY = &H4
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10
Private Address As String

Public Sub PlaySound(WavName As String)
'WavName is Id and "Sound" is the type in the resource file
Address = StrConv(LoadResData(WavName, "Sound"), vbUnicode)
sndPlaySound Address, SND_ASYNC Or SND_MEMORY
End Sub
'==================================================================

If you hav further doubts, check MSDN or post it. I am always here to help you people out.

All the Best Praveen Menon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top