下面的代码有几个问题?请各位帮帮忙改正过来。谢谢!
Function ShowNumber(OpenClose As Boolean, CommPort As Integer) As Boolean
On Error Resume Next
Dim i As Integer Dim strTemp As String
Dim commCID(1) As String
Dim Duration As Single
Dim BStop As Boolean
If OpenClose = True Then
MSComm1.CommPort = CommPort
MSComm1.PortOpen = True
End If
commCID(0) = "at#cid=" & IIf(OpenClose, 1, 0)
commCID(1) = "at#vcid=" & IIf(OpenClose, 1, 0)
MSComm1.RThreshold = 0
For i = 0 To 1
MSComm1.Output = commCID(i) & vbCr
Duration = Timer + 1
Do While BStop = False
'Ninterval = Ninterval + 1
If MSComm1.InBufferCount >= 2 Then
strTemp = MSComm1.Input
If InStr(strTemp, "OK") = 0 Then
BStop = False
ShowNumber = True
Exit Function
End If
End If
If Timer >= Duration Or Err.Number Then
Exit Do
Loop
Next i
ShowNumber = False
MSComm1.RThreshold = 1
End Function
-------------------------------------------------------------
Private Sub cmdDisable_Click()
If Not ShowNumber(False, 2) Then
MsgBox "不能开启功能", vbCritical
Else
MSComm1.PortOpen = False
MsgBox "功能已禁止!", vbInformation
End If
End Sub
Function ShowNumber(OpenClose As Boolean, CommPort As Integer) As Boolean
On Error Resume Next
Dim i As Integer Dim strTemp As String
Dim commCID(1) As String
Dim Duration As Single
Dim BStop As Boolean
If OpenClose = True Then
MSComm1.CommPort = CommPort
MSComm1.PortOpen = True
End If
commCID(0) = "at#cid=" & IIf(OpenClose, 1, 0)
commCID(1) = "at#vcid=" & IIf(OpenClose, 1, 0)
MSComm1.RThreshold = 0
For i = 0 To 1
MSComm1.Output = commCID(i) & vbCr
Duration = Timer + 1
Do While BStop = False
'Ninterval = Ninterval + 1
If MSComm1.InBufferCount >= 2 Then
strTemp = MSComm1.Input
If InStr(strTemp, "OK") = 0 Then
BStop = False
ShowNumber = True
Exit Function
End If
End If
If Timer >= Duration Or Err.Number Then
Exit Do
Loop
Next i
ShowNumber = False
MSComm1.RThreshold = 1
End Function
-------------------------------------------------------------
Private Sub cmdDisable_Click()
If Not ShowNumber(False, 2) Then
MsgBox "不能开启功能", vbCritical
Else
MSComm1.PortOpen = False
MsgBox "功能已禁止!", vbInformation
End If
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货