我有低於該代碼工作正常,通過行步驟查驗每個主機,並更新表。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