我有低于该代码工作正常,通过行步骤查验每个主机,并更新表。VBA自主对象
Sub Do_ping()
Set output = ActiveWorkbook.Worksheets(1)
With ActiveWorkbook.Worksheets(1)
Set pinger = CreateObject("WScript.Shell")
pings = 1
pingend = "FALSE"
output.Cells(2, 4) = pings
output.Cells(2, 5) = pingend
Do
Row = 2
Do
If .Cells(Row, 1) <> "" Then
result = pinger.Run("%comspec% /c ping.exe -n 1 -w 250 " _
& output.Cells(Row, 1).Value & " | find ""TTL="" > nul 2>&1", 0, True)
If (result = 0) = True Then
result = "TRUE"
Else
result = "FALSE"
End If
' result = IsConnectible(.Cells(Row, 1), 1, 1000)
output.Cells(Row, 2) = result
End If
Row = Row + 1
Loop Until .Cells(Row, 1) = ""
waitTime = 1
Start = Timer
While Timer < Start + waitTime
DoEvents
Wend
output.Cells(2, 4) = pings
output.Cells(2, 5) = pingend
pings = pings + 1
Loop Until pingend = "TRUE"
End With
End Sub
但假设我有50个设备,其中40个设备已关闭。因为它是顺序的,所以我必须等待ping在这些设备上超时,因此一次传递可能需要很长时间。
我在VBA可以创建一个对象,我可以创造的,每个ping一台独立的主机乘实例,然后简单的循环,虽然对象拉回从他们真/假财产。
我不知道该怎么可能,这是或你如何应对VBA类。
我要像
set newhostping = newobject(pinger)
pinger.hostname = x.x.x.x
一些事情来设置对象,然后对象将有逻辑
do
ping host x.x.x.x
if success then outcome = TRUE
if not success then outcome = FALSE
wait 1 second
loop
所以回到主代码,我可以只使用
x = pinger.outcome
给我主机的当前状态,而不需要等待当前的ping操作完成。这将只返回最后完成的尝试
没有任何一个有他们可以分享任何代码或想法的结果呢?
谢谢
DevilWAH
您是否考虑过正确缩进代码以使其他人更容易阅读和理解? – 2012-02-25 20:36:12