comparing date values

pjfatboy

Active member
Joined
Nov 30, 2012
Messages
35
Programming Experience
Beginner
I am new to .net and I found this code several times in a Google search. Could someone please tell me why this code is not working? I checked several times and the file is in this location. Sorry, the wav file is not playing. Also could someone tell me how to place code in a Thread? DimappPathAsString = Application.StartupPath()
IfAlarmtxt.Text <> ""Then
IfCDate(Datelb.Text) = AlarmDTP.ValueAndTimelb.Text = Alarmtxt.TextThen
My.Computer.Audio.Play(appPath & "\Alarm2.wav", AudioPlayMode.Background)
EndIf
EndIf
 
Last edited:
Turn off the rich text editing mode and you wrap the code in
VB.NET:
 tags. You should be using the Parse methods from the DateTime class though. TryParse if there's a chance that these strings are not parsable as DateTime objects... What is AlarmDTP?
 
DateTimePicker. My problem is that the Alarm wav file does not play. I put a brake in the code and line four the Audio.Play line is read and the file is there but it doesn't get played. The file is not corrupt because I can double click the file in the resources and it plays just fine.
 
Instead of CDate() try the DateTime Parse methods like I mentioned. Otherwise, test with a simple display to see if that is actually trying to be played. Change the if statement a bit:
VB.NET:
If CDate(Datelb.Text) = AlarmDTP.Value And Timelb.Text = Alarmtxt.Text Then
    MessageBox.Show("True")
EndIf

I wouldn't suggest this at all though: CDate(Datelb.Text) = AlarmDTP.Value And Timelb.Text = Alarmtxt.Text

Did you modify your code since my last reply at all? Where are you at? You can explain to me all the issues you're having, but I can't help unless you provide me more details to work with.

Also through the code, it'd be easiest to check if it exists. Sometimes I see people trying to tell me something exists, but it's not the exact location they think it's checking. So try this:
VB.NET:
MessageBox.Show(System.IO.File.Exists(appPath & "\Alarm2.wav").ToString)

Now this leads me to another point: You should actually be checking for the File's existence through some code logic before you try using a file for any purpose. If it doesn't exist, then it may be a good idea to place some form of user notification in there so that they know what the problem is as well.
 
Ok, I get a True message. I don't know what else to try. The code is right and the file exist. ???????

If you're sure the file exists, how large is this wav file? are you giving it enough time to load and play?
 
I would write it like this though:
VB.NET:
Dim appPath As String = Application.StartupPath()
If Alarmtxt.Text <> String.Empty Then
    Dim inputDate As DateTime
    If DateTime.TryParse(Datelb.Text, inputDate) Then
        If inputDate = AlarmDTP.Value AndAlso Timelb.Text = Alarmtxt.Text Then
            Dim fPath As String = appPath & "\Alarm2.wav"
            If File.Exists(fPath) Then
                My.Computer.Audio.Play(fPath, AudioPlayMode.Background)
            End If
        End If
    End If
End If

Just to give you a full example. Try playing that file without all of the junk around it though. Remove or comment out everything else but this for the time being:
VB.NET:
My.Computer.Audio.Play(appPath & "\Alarm2.wav", AudioPlayMode.Background)

See if it plays.
 
I'm beginning to think it has something to do with Windows 8 or something. That didn't work either. I even tried to start a new project with Audio.Play in the Form Load and still nothing.
 
I'm beginning to think it has something to do with Windows 8 or something. That didn't work either. I even tried to start a new project with Audio.Play in the Form Load and still nothing.

Do you get any errors? Or will it just not play? My.Computer.Audio.Play() works completely fine for me in Windows 8. Perhaps this is not a programming issue and you have your sound device turned off? I'm starting to look at all of the possibilities here... Sometimes the simplest solutions are not the ones which have been thought of, even though they may be the solution. Those times where it happens to be the simplest fix though, seems to be the hardest to figure out, because we always assume the most difficult problems for possibilities.

~Ace
 
The volume is fine, I can double click the file in the resource folder and it plays fine. If I can hear the wav file when I double click it that means my sound device is turned on right? Oh, and no errors.
 
If I can hear the wav file when I double click it that means my sound device is turned on right?

lol, yes. That's what it should mean anyways :)

No errors... (And you don't have a Try Catch block surrounding it to pretty much null out or ignore any exceptions?) You are talking about the Resource folder though too. Did you add this as a resource, or are you trying to play it from the filesystem?
 
Filesystem I guess. I put a break point on the Audio.play line of code then put my mouse over the line of code to see where the app was looking for the file and copied the file to that folder. Sorry that is not totally true, I also imported to the Resources folder.
 
Last edited:
Filesystem I guess. I put a break point on the Audio.play line of code then put my mouse over the line of code to see where the app was looking for the file and copied the file to that folder. Sorry that is not totally true, I also imported to the Resources folder.

"I also imported to the Resources folder" - Then it would not be alongside the application anyways, which is where you're looking for that audio file.

Try this:
VB.NET:
My.Computer.Audio.Play(My.Resources.Alarm2, AudioPlayMode.Background)
 
Yeah I tried that and it didn't work either. I'll try it again. Nope didn't work either. For the life of me I can't figure this one out. Code is right, the file is there, the volume is up and the line of code is read but no go. I don't know what else to try.
 
Back
Top