你是每次取temp.txt的一行来搜索是否出现text1中的字符串,如果p不为0,则p为出现目标字符串的位置。然后就要赋text2的值。为什么要在mid前 & 一个text2和vbcrlf呢?
If p <> 0 Then Text2 = Mid(s, p + Len(Text1.Text) + 1, 5)
我改了一下代码,没出现问题。
程序代码:
If p <> 0 Then Text2 = Mid(s, p + Len(Text1.Text) + 1, 5)
我改了一下代码,没出现问题。
程序代码:Private Sub Timer1_Timer()
Dim pId As Long, pHnd As Long
If Dir("C:\temp.txt") <> "" Then Kill "C:\temp.txt"
pId = Shell("cmd /c netstat -an>>C:\temp.txt", vbMinimizedFocus)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pId)
Do
Call GetExitCodeProcess(hProcess, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
Call CloseHandle(hProcess)
Text1.Text = ""
Open "c:\temp.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
p = InStr(Text1.Text, "177") '在text1中输入查找关键字
If p <> 0 Then Text3.Text = Mid(Text1.Text, p + Len("177") + 1, 2)
If Text3.Text = "80" Then Form1.Caption = "已联接中"
End Sub
大开眼界







