.NET Forum / Languages / VB.NET / December 2005
Very, very, very new user needs help.
|
|
Thread rating:  |
Jack Sadie - 29 Dec 2005 11:14 GMT 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
 Signature Regards, Jack Sadie jaxalad-buying@yahooREMOVE.co.uk
Armin Zingler - 29 Dec 2005 11:28 GMT > 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, [quoted text clipped - 23 lines] > "sndPlaySoundA" (ByVal FileName As String, _ > ByVal Flags As Long) As Long Private Declare Function sndPlaySound Lib "winmm.dll" Alias _ "sndPlaySoundA" (ByVal FileName As String, _ ByVal Flags As Integer) As Boolean
> Dim myDate As String > [quoted text clipped - 19 lines] > End Select > End Sub 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
Armin Zingler - 29 Dec 2005 11:59 GMT > day = Weekday(Now, FirstDayOfWeek.System) 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
Cor Ligthert [MVP] - 29 Dec 2005 11:49 GMT 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
Herfried K. Wagner [MVP] - 29 Dec 2005 11:56 GMT "Jack Sadie" <jacksadie@btinternet.com> schrieb:
>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) 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() ///
 Signature M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Jack Sadie - 29 Dec 2005 13:06 GMT 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!! =:>( "
 Signature Regards, Jack Sadie jaxalad-buying@yahooREMOVE.co.uk
>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 [quoted text clipped - 45 lines] > End Select > End Sub Armin Zingler - 29 Dec 2005 13:11 GMT > THANKS TO ARMIN, COR AND HERFRIED. > I appreciate the trouble each of you has taken. I'm not certain I [quoted text clipped - 4 lines] > Armin, > Sorry but I really am so newbie I don't even know where to start ! You're welcome!
> Do I just open a new project, click on View/code and enter the > following between "Public Class Form1" and " End Class":- Yes - but leave the "Windows forms designer generated code" in place. ;)
> Private Declare Function sndPlaySound Lib "winmm.dll" Alias _ > "sndPlaySoundA" (ByVal FileName As String, _ [quoted text clipped - 11 lines] > > After that what do I do? 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?
> (Are you sorry you started to help me!! =:>( " No, I don't feel sorry. :-)
Armin
Jack Sadie - 29 Dec 2005 17:58 GMT 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.
 Signature Regards, Jack Sadie jaxalad-buying@yahooREMOVE.co.uk
>> THANKS TO ARMIN, COR AND HERFRIED. >> I appreciate the trouble each of you has taken. I'm not certain I [quoted text clipped - 37 lines] > > Armin Armin Zingler - 29 Dec 2005 19:01 GMT > I then shut down and re-started my computer but there was no sound > played, so I obviously haven't set up correctly yet. Did you add your application to the autostart menu?
> 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. 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 - 29 Dec 2005 23:03 GMT 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.
 Signature Regards, Jack Sadie jaxalad-buying@yahooREMOVE.co.uk
>> I then shut down and re-started my computer but there was no sound >> played, so I obviously haven't set up correctly yet. [quoted text clipped - 15 lines] > > Armin Armin Zingler - 31 Dec 2005 10:30 GMT > 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. 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.
> Changed line as requested - no message true or false. 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.
> 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. Have a nice time. :-)
Armin
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|