Connecting Tech Pros Worldwide Help | Site Map

Very, very, very new user needs help.

Jack Sadie
Guest
 
Posts: n/a
#1: Dec 29 '05
I am using Windows XP and I have found out how to substitute my own wav
sound for the Microsoft default sound when my computer starts, but now I
want to go a step further. I have created 7 different wave files

(C:\Start sound\day1.wav to C:\Start sound\day7.wav respectively)

and want to have a different one open according to the day of the week - the
"day1.wav" opening on Mondays and the "day2.wav" on Tuesdays and so on.

I have downloaded Visual Basic Express edition but I need to have a routine
created which I don't have the expertise to do.
I was very kindly given the following routine in a VB6 ng but because it
won't work in the Express Edition, they advised me to try a dotnet group for
the correct code. I have included it below because it just might be easily
amended by someone who is familiar but it may need to be completely
re-composed.

Can any kind person assist or point me in the right direction if this is the
wrong ng.
Thanks so much.


Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal FileName As String, _
ByVal Flags As Long) As Long
Dim myDate As String

Private Sub Form_Load()

myDate = Format(Now, "dddd")
Debug.Print myDate
Select Case myDate
Case "Monday"
Call sndPlaySound("C:\start sound\day1.wav", 1)
Case "Tuesday"
Call sndPlaySound("C:\start sound\day2.wav", 1)
Case "Wednesday"
Call sndPlaySound("C:\start sound\day3.wav", 1)
Case "Thursday"
Call sndPlaySound("C:\start sound\day4.wav", 1)
Case "Friday"
Call sndPlaySound("C:\start sound\day5.wav", 1)
Case "Saturday"
Call sndPlaySound("C:\start sound\day6.wav", 1)
Case "Sunday"
Call sndPlaySound("C:\start sound\day7.wav", 1)
End Select
End Sub


--
Regards, Jack Sadie
jaxalad-buying@yahooREMOVE.co.uk



Cor Ligthert [MVP]
Guest
 
Posts: n/a
#2: Dec 29 '05

re: Very, very, very new user needs help.


Jack,

In VB 2005 there are more methods to play a wav file.

You can use DirectX
You can use My.Computer.Audio.Play(fileName)
http://msdn2.microsoft.com/en-us/library/cf1shcah.aspx

You can do it in the way as you see in that VB6 sample, because that in VB6
a long is 32bits you have to change that "long in "Int32".

And there is even another method, I have to search for it, it comes not
direct in my mind, however because that I assume that you will use that
Audio.Play (because you should try to avoid using Win32 API's and DirectX is
the hard way to go), I don't do that.

I hope this helps,

Cor


Armin Zingler
Guest
 
Posts: n/a
#3: Dec 29 '05

re: Very, very, very new user needs help.


"Jack Sadie" <jacksadie@btinternet.com> schrieb[color=blue]
> I am using Windows XP and I have found out how to substitute my own
> wav sound for the Microsoft default sound when my computer starts,
> but now I want to go a step further. I have created 7 different wave
> files
>
> (C:\Start sound\day1.wav to C:\Start sound\day7.wav respectively)
>
> and want to have a different one open according to the day of the
> week - the "day1.wav" opening on Mondays and the "day2.wav" on
> Tuesdays and so on.
>
> I have downloaded Visual Basic Express edition but I need to have a
> routine created which I don't have the expertise to do.
> I was very kindly given the following routine in a VB6 ng but
> because it won't work in the Express Edition, they advised me to try
> a dotnet group for the correct code. I have included it below
> because it just might be easily amended by someone who is familiar
> but it may need to be completely re-composed.
>
> Can any kind person assist or point me in the right direction if
> this is the wrong ng.
> Thanks so much.
>
>
> Option Explicit
> Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
> "sndPlaySoundA" (ByVal FileName As String, _
> ByVal Flags As Long) As Long[/color]


Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal FileName As String, _
ByVal Flags As Integer) As Boolean

[color=blue]
> Dim myDate As String
>
> Private Sub Form_Load()
>
> myDate = Format(Now, "dddd")
> Debug.Print myDate
> Select Case myDate
> Case "Monday"
> Call sndPlaySound("C:\start sound\day1.wav", 1)
> Case "Tuesday"
> Call sndPlaySound("C:\start sound\day2.wav", 1)
> Case "Wednesday"
> Call sndPlaySound("C:\start sound\day3.wav", 1)
> Case "Thursday"
> Call sndPlaySound("C:\start sound\day4.wav", 1)
> Case "Friday"
> Call sndPlaySound("C:\start sound\day5.wav", 1)
> Case "Saturday"
> Call sndPlaySound("C:\start sound\day6.wav", 1)
> Case "Sunday"
> Call sndPlaySound("C:\start sound\day7.wav", 1)
> End Select
> End Sub[/color]



Private Sub Form_Load()
dim day as integer
dim filename as string

day = Weekday(Now, FirstDayOfWeek.System)
filename = "C:\start sound\day" & day & ".wav"
sndPlaySound(filename, 1)

End Sub


Armin
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#4: Dec 29 '05

re: Very, very, very new user needs help.


"Jack Sadie" <jacksadie@btinternet.com> schrieb:[color=blue]
>I am using Windows XP and I have found out how to substitute my own wav
> sound for the Microsoft default sound when my computer starts, but now I
> want to go a step further. I have created 7 different wave files
>
> (C:\Start sound\day1.wav to C:\Start sound\day7.wav respectively)[/color]

Untested (requires .NET 2.0 (VS 2005)):

\\\
Imports System.Media
....
Dim FileName As String
Select Case Now.DayOfWeek
Case DayOfWeek.Monday
FileName = "Monday.wav"
Case DayOfWeek.Tuesday
FileName = "Tuesday.wav"
Case DayOfWeek.Wednesday
...
Case DayOfWeek.Thursday
...
Case DayOfWeek.Saturday
...
Case DayOfWeek.Sunday
...
End Select
Dim Player As New SoundPlayer( _
Path.Combine(My.Application.Info.DirectoryPath, FileName) _
)
Player.Play()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Armin Zingler
Guest
 
Posts: n/a
#5: Dec 29 '05

re: Very, very, very new user needs help.


"Armin Zingler" <az.nospam@freenet.de> schrieb[color=blue]
> day = Weekday(Now, FirstDayOfWeek.System)[/color]

Addition: Don't believe the online help to 'Weekday'. It says the return
value of Weekday is equal to the value of the FirstDayOfWeek enumeration.
That's wrong. If it was true, the return type of Weekday could be
FirstDayOfWeek, not Integer. Actually, Weekday returns the number of the day
in the week, i.e. 1 for the 1st day, 2 for the 2nd, 3 for the 3rd etc. If
Monday is the first day, it returns 1 for Monday. If Sunday is the first day
of the week, it returns 1 for Sunday.


Armin

Jack Sadie
Guest
 
Posts: n/a
#6: Dec 29 '05

re: Very, very, very new user needs help.


THANKS TO ARMIN, COR AND HERFRIED.
I appreciate the trouble each of you has taken. I'm not certain I quite
understand how to employ (or deploy) any of your answers at this stage.
However I shall be experimenting and will report back in due course.
For starters in the meantime :-

Armin,
Sorry but I really am so newbie I don't even know where to start !

Do I just open a new project, click on View/code and enter the following
between "Public Class Form1" and " End Class":-

Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal FileName As String, _
ByVal Flags As Integer) As Boolean

Private Sub Form_Load()
dim day as integer
dim filename as string

day = Weekday(Now, FirstDayOfWeek.System)
filename = "C:\start sound\day" & day & ".wav"
sndPlaySound(filename, 1)

End Sub

After that what do I do?
(Are you sorry you started to help me!! =:>( "
--
Regards, Jack Sadie
jaxalad-buying@yahooREMOVE.co.uk


"Jack Sadie" <jacksadie@btinternet.com> wrote in message
news:wZWdnQSNr5mdWC7enZ2dnUVZ8qCdnZ2d@pipex.net...[color=blue]
>I am using Windows XP and I have found out how to substitute my own wav
>sound for the Microsoft default sound when my computer starts, but now I
>want to go a step further. I have created 7 different wave files
>
> (C:\Start sound\day1.wav to C:\Start sound\day7.wav respectively)
>
> and want to have a different one open according to the day of the week -
> the "day1.wav" opening on Mondays and the "day2.wav" on Tuesdays and so
> on.
>
> I have downloaded Visual Basic Express edition but I need to have a
> routine created which I don't have the expertise to do.
> I was very kindly given the following routine in a VB6 ng but because it
> won't work in the Express Edition, they advised me to try a dotnet group
> for the correct code. I have included it below because it just might be
> easily amended by someone who is familiar but it may need to be completely
> re-composed.
>
> Can any kind person assist or point me in the right direction if this is
> the wrong ng.
> Thanks so much.
>
>
> Option Explicit
> Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
> "sndPlaySoundA" (ByVal FileName As String, _
> ByVal Flags As Long) As Long
> Dim myDate As String
>
> Private Sub Form_Load()
>
> myDate = Format(Now, "dddd")
> Debug.Print myDate
> Select Case myDate
> Case "Monday"
> Call sndPlaySound("C:\start sound\day1.wav", 1)
> Case "Tuesday"
> Call sndPlaySound("C:\start sound\day2.wav", 1)
> Case "Wednesday"
> Call sndPlaySound("C:\start sound\day3.wav", 1)
> Case "Thursday"
> Call sndPlaySound("C:\start sound\day4.wav", 1)
> Case "Friday"
> Call sndPlaySound("C:\start sound\day5.wav", 1)
> Case "Saturday"
> Call sndPlaySound("C:\start sound\day6.wav", 1)
> Case "Sunday"
> Call sndPlaySound("C:\start sound\day7.wav", 1)
> End Select
> End Sub
>
>
> --
> Regards, Jack Sadie
> jaxalad-buying@yahooREMOVE.co.uk
>
>
>[/color]



Armin Zingler
Guest
 
Posts: n/a
#7: Dec 29 '05

re: Very, very, very new user needs help.


"Jack Sadie" <jacksadie@btinternet.com> schrieb[color=blue]
> THANKS TO ARMIN, COR AND HERFRIED.
> I appreciate the trouble each of you has taken. I'm not certain I
> quite understand how to employ (or deploy) any of your answers at
> this stage. However I shall be experimenting and will report back in
> due course. For starters in the meantime :-
>
> Armin,
> Sorry but I really am so newbie I don't even know where to start ![/color]

You're welcome!
[color=blue]
> Do I just open a new project, click on View/code and enter the
> following between "Public Class Form1" and " End Class":-[/color]


Yes - but leave the "Windows forms designer generated code" in place. ;)

[color=blue]
> Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
> "sndPlaySoundA" (ByVal FileName As String, _
> ByVal Flags As Integer) As Boolean
>
> Private Sub Form_Load()
> dim day as integer
> dim filename as string
>
> day = Weekday(Now, FirstDayOfWeek.System)
> filename = "C:\start sound\day" & day & ".wav"
> sndPlaySound(filename, 1)
>
> End Sub
>
> After that what do I do?[/color]

Start to see if it works. Did you try? Did it work? If not, was there an
error? If yes, when compiling or at run-time (errors @ run-time are called
'Exceptions' now). If you get an exception, what's the message?
[color=blue]
> (Are you sorry you started to help me!! =:>( "[/color]

No, I don't feel sorry. :-)


Armin

Jack Sadie
Guest
 
Posts: n/a
#8: Dec 29 '05

re: Very, very, very new user needs help.


ok Armin
Entered the code. Couldn't see how to save it so I decided to close and it
then asked if I wanted to save, so I did so in the folder offered :-
F:\Visual Studio 2005\Projects\StartSound Project\Start Sound Project.sln

I then shut down and re-started my computer but there was no sound played,
so I obviously haven't set up correctly yet.
I then re-opened the project and pressed F5, which I believe starts the
program running so that any errors are displayed. None showed, so I have
nothing to more to report.
Thanks for keeping with me.
--
Regards, Jack Sadie
jaxalad-buying@yahooREMOVE.co.uk
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:uD8Bo4HDGHA.1032@TK2MSFTNGP11.phx.gbl...[color=blue]
> "Jack Sadie" <jacksadie@btinternet.com> schrieb[color=green]
>> THANKS TO ARMIN, COR AND HERFRIED.
>> I appreciate the trouble each of you has taken. I'm not certain I
>> quite understand how to employ (or deploy) any of your answers at
>> this stage. However I shall be experimenting and will report back in
>> due course. For starters in the meantime :-
>>
>> Armin,
>> Sorry but I really am so newbie I don't even know where to start ![/color]
>
> You're welcome!
>[color=green]
>> Do I just open a new project, click on View/code and enter the
>> following between "Public Class Form1" and " End Class":-[/color]
>
>
> Yes - but leave the "Windows forms designer generated code" in place. ;)
>
>[color=green]
>> Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
>> "sndPlaySoundA" (ByVal FileName As String, _
>> ByVal Flags As Integer) As Boolean
>>
>> Private Sub Form_Load()
>> dim day as integer
>> dim filename as string
>>
>> day = Weekday(Now, FirstDayOfWeek.System)
>> filename = "C:\start sound\day" & day & ".wav"
>> sndPlaySound(filename, 1)
>>
>> End Sub
>>
>> After that what do I do?[/color]
>
> Start to see if it works. Did you try? Did it work? If not, was there an
> error? If yes, when compiling or at run-time (errors @ run-time are called
> 'Exceptions' now). If you get an exception, what's the message?
>[color=green]
>> (Are you sorry you started to help me!! =:>( "[/color]
>
> No, I don't feel sorry. :-)
>
>
> Armin
>[/color]


Armin Zingler
Guest
 
Posts: n/a
#9: Dec 29 '05

re: Very, very, very new user needs help.


"Jack Sadie" <jacksadie@btinternet.com> schrieb[color=blue]
> I then shut down and re-started my computer but there was no sound
> played, so I obviously haven't set up correctly yet.[/color]

Did you add your application to the autostart menu?
[color=blue]
> I then re-opened the project and pressed F5, which I believe starts
> the program running so that any errors are displayed. None showed,
> so I have nothing to more to report.
> Thanks for keeping with me.[/color]

Change the line from
sndPlaySound(filename, 1)
to
Msgbox(sndPlaySound(filename, 1))

Start the application again. Do you get a message saying "True" or "False"?



Armin

Jack Sadie
Guest
 
Posts: n/a
#10: Dec 29 '05

re: Very, very, very new user needs help.


Tried to add application to start menu, but trouble is I don't really know
which file to add. Could it be one called WindowsApplication1.vbproj ?
That's the one I used.

Changed line as requested - no message true or false.

Rebooted but still no sound. I think I may delete all and start again taking
more trouble to record file names and their location.
In any case I'm leaving London tomorrow for a couple of days to Stratford on
Avon to see some plays at the Shakespeare Theatre.
I'll post back on my return and, if you have no objection Armin (email me
if you would prefer no direct contact), will send an email to advise you at
that time.
Meanwhile Happy New Year to all.
--
Regards, Jack Sadie
jaxalad-buying@yahooREMOVE.co.uk
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:uXsO6rKDGHA.2912@tk2msftngp13.phx.gbl...[color=blue]
> "Jack Sadie" <jacksadie@btinternet.com> schrieb[color=green]
>> I then shut down and re-started my computer but there was no sound
>> played, so I obviously haven't set up correctly yet.[/color]
>
> Did you add your application to the autostart menu?
>[color=green]
>> I then re-opened the project and pressed F5, which I believe starts
>> the program running so that any errors are displayed. None showed,
>> so I have nothing to more to report.
>> Thanks for keeping with me.[/color]
>
> Change the line from
> sndPlaySound(filename, 1)
> to
> Msgbox(sndPlaySound(filename, 1))
>
> Start the application again. Do you get a message saying "True" or
> "False"?
>
>
>
> Armin
>[/color]


Armin Zingler
Guest
 
Posts: n/a
#11: Dec 31 '05

re: Very, very, very new user needs help.


"Jack Sadie" <jacksadie@btinternet.com> schrieb[color=blue]
> Tried to add application to start menu, but trouble is I don't
> really know which file to add. Could it be one called
> WindowsApplication1.vbproj ? That's the one I used.[/color]


I thought you know that applications are Exe files. Add a link to
WindowsApplication1.exe (it's in the 'bin' sub folder of your project) to
the start menu, but before doing this I suggest to solve the problem. If it
doesn't work in the IDE, it also won't from the start menu.
[color=blue]
> Changed line as requested - no message true or false.[/color]

I missed an important point. Change the line
Private Sub Form_Load()
to
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

Now it should work. Don't forget to build the exe before adding it to the
start menu, but this is done anyway if you first test it in the IDE.
[color=blue]
> Rebooted but still no sound. I think I may delete all and start again
> taking more trouble to record file names and their location.
> In any case I'm leaving London tomorrow for a couple of days to Stratford
> on Avon to see some plays at the Shakespeare Theatre.[/color]

Have a nice time. :-)


Armin

Closed Thread