SWAYWOOD 发表于 2004-4-25 21:51:00

[求助]关于VBA

各位前辈,我没学过VBA,但听说VBA能实现我这种功能,


请帮个忙


我想在打开CAD的时候,就装载该程序,


这个程序的功能是:在上午10点时,检测服务器上的一台电脑


也就是说,这个程序在开启之后,就一直在后台运行,直到10点,发生检测电脑的事件!

efan2000 发表于 2004-4-27 09:42:00

加载可以在acad.dvb中,或者在acaddoc.lsp编写代码来实现。定时执行,可以使用定时器,也可以通过循环来操作。如:Sub Test()
       If Hour(Now) > 10 Then Exit Sub
       Do While Hour(Now) < 10
               DoEvents '空执行
       Loop
       Ping "192.168.0.1"
End Sub检测网络中的某一台电脑,实际上是Ping的操作,如果Ping的通,说明是连通的。Const SOCKET_ERROR = 0
Private Type WSAdata
       wVersion As Integer
       wHighVersion As Integer
       szDescription(0 To 255) As Byte
       szSystemStatus(0 To 128) As Byte
       iMaxSockets As Integer
       iMaxUdpDg As Integer
       lpVendorInfo As Long
End Type
Private Type Hostent
       h_name As Long
       h_aliases As Long
       h_addrtype As Integer
       h_length As Integer
       h_addr_list As Long
End Type
Private Type IP_OPTION_INFORMATION
       TTL As Byte
       Tos As Byte
       Flags As Byte
       OptionsSize As Long
       OptionsData As String * 128
End Type
Private Type IP_ECHO_REPLY
       Address(0 To 3) As Byte
       Status As Long
       RoundTripTime As Long
       DataSize As Integer
       Reserved As Integer
       data As Long
       Options As IP_OPTION_INFORMATION
End Type
Private Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal HostName As String) As Long
Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequired&, lpWSAdata As WSAdata) As Long
Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal HANDLE As Long) As Boolean
Private Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As Long, ByVal DestAddress As Long, ByVal RequestData As String, ByVal RequestSize As Integer, RequestOptns As IP_OPTION_INFORMATION, ReplyBuffer As IP_ECHO_REPLY, ByVal ReplySize As Long, ByVal TimeOut As Long) As Boolean
Private Sub Form_Load()
       'KPD-Team 2000
       'URL: http://www.allapi.net/
       'E-Mail: KPDTeam@Allapi.net
       Const HostName = "www.allapi.net"
       Dim hFile As Long, lpWSAdata As WSAdata
       Dim hHostent As Hostent, AddrList As Long
       Dim Address As Long, rIP As String
       Dim OptInfo As IP_OPTION_INFORMATION
       Dim EchoReply As IP_ECHO_REPLY
       Call WSAStartup(&H101, lpWSAdata)
       If GetHostByName(HostName + String(64 - Len(HostName), 0)) <> SOCKET_ERROR Then
               CopyMemory hHostent.h_name, ByVal GetHostByName(HostName + String(64 - Len(HostName), 0)), Len(hHostent)
               CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
               CopyMemory Address, ByVal AddrList, 4
       End If
       hFile = IcmpCreateFile()
       If hFile = 0 Then
               MsgBox "Unable to Create File Handle"
               Exit Sub
       End If
       OptInfo.TTL = 255
       If IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000) Then
               rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
       Else
               MsgBox "Timeout"
       End If
       If EchoReply.Status = 0 Then
               MsgBox "Reply from " + HostName + " (" + rIP + ") recieved after " + Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
       Else
               MsgBox "Failure ..."
       End If
       Call IcmpCloseHandle(hFile)
       Call WSACleanup
End Sub
这是一个Ping操作的例子,可以参考一下。

SWAYWOOD 发表于 2004-4-28 12:16:00

多谢了,如果是找一个文件夹是否会简单一些呢?


有关定时器的使用的简单程序有吗?

雪山飞狐_lzh 发表于 2004-4-28 12:38:00

用Shell调用Dos命令Ping并将结果输出到文件,再根据文件内容判断是否Ping通

SWAYWOOD 发表于 2004-4-29 19:52:00

楼上的能说清楚点么?

yuangw1234 发表于 2006-5-5 22:03:00

<P>你们的VBA学得真让我偑服,面面俱到</P>
页: [1]
查看完整版本: [求助]关于VBA