2014-07-18 64 views
-1

我有一些电脑调制解调器和其他没有使用相同的数据库。他们需要确定是否安装了调制解调器。我在互联网上发现由KHaled El-Menshawy创建的代码,它有可能做我想做的事情,但我得到一个“Object required”错误。我认为这是一个简单的解决方法,但我不知道应该如何声明这个对象。任何人都可以找出丢失的代码?这里是他的代码:检查调制解调器

Public Function CheckModem() 
On Error GoTo Errr 
If ProgBar.Value = 100 Then 
    ProgBar.Value = 0 
End If 
Port = 1 
PortinG: 
MSComm1.CommPort = Port 
MSComm1.PortOpen = True 
ProgBar.Value = ProgBar.Value + 20 
Label1.Caption = ProgBar.Value & "%" 
Form1.MSComm1.Settings = "9600,N,8,1" 
     MSComm1.Output = "AT" + Chr$(13) 
     X = 1 

     Do: DoEvents 
      X = X + 1 
      If X = 1000 Then MSComm1.Output = "AT" + Chr$(13) 
      If X = 2000 Then MSComm1.Output = "AT" + Chr$(13) 
      If X = 3000 Then MSComm1.Output = "AT" + Chr$(13) 
      If X = 4000 Then MSComm1.Output = "AT" + Chr$(13) 
      If X = 5000 Then MSComm1.Output = "AT" + Chr$(13) 
      If X = 6000 Then MSComm1.Output = "AT" + Chr$(13) 

      If X = 7000 Then 
      MSComm1.PortOpen = False 
      Port = Port + 1 
      GoTo PortinG: 

      If MSComm1.CommPort >= 6 Then 
Errr: 
MsgBox "Can't Find Modem" 
GoTo done 
End If 
End If 

Loop Until MSComm1.InBufferCount >= 2 

instring = MSComm1.Input 
MSComm1.PortOpen = False 
ProgBar.Value = 100 
Label1.Caption = ProgBar.Value & "%" 
Text1.Text = "com" & Port 'MSComm1.CommPort & instring 
MsgBox "Modem found On Com" & Port 

done: 
End Function 
+0

'MSComm1'从哪里来? – serakfalcon

+0

我不知道MSComm1从哪里来。此代码超出了我的VBA体验。我希望在工作时插入它,然后弄清它是如何工作的。我了解端口和“AT”代码,但不知道如何回答你的问题。它看起来像一些声明丢失。任何想法如何使这项工作? – Rod

回答

0

MsComm1,如果你只是复制和代码粘贴看起来是一个MsComm control object。您必须将其添加为表单的附加控件,然后才能访问其属性。

我建议避免复制和粘贴代码,你不明白,试着了解它在做什么,为什么。或者,this link(来自this question)给出了一个完全不同的方法来完成它,避免了将控件添加到表单中的需要。