代码如下:Dim TmpFile As String, TmpStr As String
Dim StrIndex As Integer
Dim cmdstr
Dim count As String
Dim sFile As Variant
IsLinkNet = False
TmpFile = App.Path & "\ip.txt"
MsgBox TmpFile
If Dir(TmpFile) <> "" Then Kill TmpFile
cmdstr = "cmd /c ping " & IP & ">" & TmpFile
Shell cmdstr, vbHide
Open TmpFile For Input As #1
Do Until EOF(1)
Dim StrIndex As Integer
Dim cmdstr
Dim count As String
Dim sFile As Variant
IsLinkNet = False
TmpFile = App.Path & "\ip.txt"
MsgBox TmpFile
If Dir(TmpFile) <> "" Then Kill TmpFile
cmdstr = "cmd /c ping " & IP & ">" & TmpFile
Shell cmdstr, vbHide
Open TmpFile For Input As #1
Do Until EOF(1)
如果不在,要保证他们是在同一文件夹下
'而按F8单步执行的时候,有时间停留,所以shell命令已经执行完毕。Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Dim StrIndex As Integer
Dim cmdstr
Dim count As String
Dim sFile As Variant
TmpFile = App.Path & "\ip.txt"
If Dir(TmpFile) <> "" Then Kill TmpFile
cmdstr = "cmd /c ping " & IP & ">" & TmpFile
Shell cmdstr, vbHidesleep 1000 <-------------- '让程序在此停止1秒钟,等shell命令执行完Open TmpFile For Input As #1
Do Until EOF(1)
.....
这样:
do
If Dir(TmpFile) <> "" Then Kill TmpFile
loop until dir(Tmpfile)=""
If Dir(TmpFile) <> "" Then Kill TmpFile
do
loop until dir(Tmpfile)=""
其中 openporcess返回进程句柄,参数由shell返回的id指定
waitforsingleobject传递进程句柄做参数, 程序将组塞到这里直到shell执行完毕