vb貌似代码正确,却放不出声音

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:00:07
Dim a As Integer
Private Sub Form_Load()
Timer1.Enabled = True
a = 0
WindowsMediaPlayer1.URL = App.Path & "SentinelResearchComplete1.wav"
WindowsMediaPlayer1.Controls.stop
End Sub
Private Sub Timer1_Timer()
a = MsgBox("更新完毕,查看", , "update每日提示")
If a = 1 Then
Timer2.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
WindowsMediaPlayer1.Controls.play
Timer2.Enabled = False
Timer1.Enabled = False
End Sub

Dim a As Integer, MyPath As String
Private Sub Form_Load()
MyPath = App.Path
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
Timer1.Enabled = True
a = 0
WindowsMediaPlayer1.URL = MyPath & "SentinelResearchComplete1.wav"
WindowsMediaPlayer1.Controls.stop
End Sub
Private Sub Timer1_Timer()
a = MsgBox("更新完毕,查看", , "update每日提示")
If a = 1 Then
Timer2.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
WindowsMediaPlayer1.Controls.play
Timer2.Enabled = False
Timer1.Enabled = False
End Sub

你没有考虑到App.Path的问题。当在磁盘根目录时候是X:\如果不是最后面的没有\

Public Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVallpszName As String, _
ByValhModule As Long, ByValdwFlags As Long) _
As Long

不用控件用这个api

小儿科

上面骗人的LJ