初始化定义:
MCIStatusLen = 15
MCIStatus = String(MCIStatusLen + 1, " ")
由于MCIStatus '返回"stopped ",实际要求返回"stopped",中间多了八个空格,所以if语句Replace(Trim(MCIStatus), " ", "") = "stopped" 判断时为False,我用Len(Replace(Trim(MCIStatus), " ", ""))判断其长度,发现还是15,所以请教大家有什么办法让其返回是True!
源代码参考如下:Private Sub Timer1_Timer()
Dim strTitle As String
Dim hdl As Long
Dim MCIStatusLen As Integer
Dim MCIStatus As String
'*********************************************检测播放状态
If IsMusicOn = True Then
MCIStatusLen = 15
MCIStatus = String(MCIStatusLen + 1, " ")
RetValue = mciSendString("STATUS BackgroundMusic MODE", MCIStatus, MCIStatusLen, 0)
End If
'*********************************************检测结束
strTitle = Space(765) '定义接收字串
hdl = GetForegroundWindow ' hwnd is the handle to the foreground window
GetWindowText hdl, strTitle, 1024
Debug.Print Left(Replace(strTitle, " ", ""), 9) = "Messenger" '返回true
Debug.Print Len(Replace(Trim(MCIStatus), " ", "")) '返回15
Debug.Print MCIStatus '返回"stopped "
If Left(Replace(strTitle, " ", ""), 9) = "Messenger" And Replace(Trim(MCIStatus) = "stopped" Then '如何让 MCIStatus = "stopped"这句返回也是True
Call Startpaly
ElseIf Left(Replace(strTitle, " ", ""), 9) <> "Messenger" And S = "playing" Then
Call Stoppaly
End If
End Sub
MCIStatusLen = 15
MCIStatus = String(MCIStatusLen + 1, " ")
由于MCIStatus '返回"stopped ",实际要求返回"stopped",中间多了八个空格,所以if语句Replace(Trim(MCIStatus), " ", "") = "stopped" 判断时为False,我用Len(Replace(Trim(MCIStatus), " ", ""))判断其长度,发现还是15,所以请教大家有什么办法让其返回是True!
源代码参考如下:Private Sub Timer1_Timer()
Dim strTitle As String
Dim hdl As Long
Dim MCIStatusLen As Integer
Dim MCIStatus As String
'*********************************************检测播放状态
If IsMusicOn = True Then
MCIStatusLen = 15
MCIStatus = String(MCIStatusLen + 1, " ")
RetValue = mciSendString("STATUS BackgroundMusic MODE", MCIStatus, MCIStatusLen, 0)
End If
'*********************************************检测结束
strTitle = Space(765) '定义接收字串
hdl = GetForegroundWindow ' hwnd is the handle to the foreground window
GetWindowText hdl, strTitle, 1024
Debug.Print Left(Replace(strTitle, " ", ""), 9) = "Messenger" '返回true
Debug.Print Len(Replace(Trim(MCIStatus), " ", "")) '返回15
Debug.Print MCIStatus '返回"stopped "
If Left(Replace(strTitle, " ", ""), 9) = "Messenger" And Replace(Trim(MCIStatus) = "stopped" Then '如何让 MCIStatus = "stopped"这句返回也是True
Call Startpaly
ElseIf Left(Replace(strTitle, " ", ""), 9) <> "Messenger" And S = "playing" Then
Call Stoppaly
End If
End Sub
解决方案 »
- 已经知道按钮的句柄,如何判断此按钮是否被按下?
- 打印问题
- vb监视目录,一但有文件加入,list显示文件名,若有两个文件以上,list分行显示文件(每个文件名占一行)
- 遍历相同控件的问题
- 求API函数 用以获得cpu和显卡的风扇转速,工作电压等系统当前信息
- VB介面该怎么做啊
- 求教:msflexgrid中单元格的数字相加减,得出奇怪的结果
- 请问谁有平面按钮
- 我下载了Installshield6.31及相关的东方语言包,使用后无法选择语言,怎么回事啊?
- 请问用ADO实现SQL交叉查询,将三个表中的记录查出后合并在一个记录集中
- 上次别人回了一个错的答案给我,大家看看怎样写
- HTML怎样调用在OCX usercontrol里面的过程和函数呢?
可以用下边的方式查看字符串中空白字符ASCII码:
dim i as integer
for i=1 to len(mcistatus)
debug.print asc(mid(MCIStatus,i,1))
next
if MCIStatus Like "stopped*" then
==>
LCase(Trim(Replace(MCIStatus,chr(0),""))="stopped"
For i = 1 To Len(a)
MsgBox Mid(a,i,1) & " === " & asc(Mid(a,i,1))
Next 比较一下那些空格是不是32