新手如何开直播赚钱:vb dim急 !!在线等!!2次发.上次没明白,你们在看看好不

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 00:41:47
Private Sub Command1_Click()
Dim a As Integer
For a = 1 To 254
Shell "cmd /c ping 192.168.0." & a & ">c:\" & a & ".txt"
Next a
End Sub
就可以,但是一次要开254个CMD,电脑都快死机了

Private Sub Command1_Click()
Dim a As Integer
For a = 1 To 254
Shell "cmd /c ping 192.168.0." & a & ">>c:\1.txt"
Next a
End Sub
为什么这样就不行了啊
!!不知道怎么和你们在这里谈,方便留QQ吗,也不知道怎么给你们积分,最好你们说详细点,我刚刚学的!!

上次不是告诉地你,不能直接用SHELL吗?
像你这种FOR调用,前一个Shell并没正式完成下一个及下下一个都又运行了,你无法知道最终什么时候真正完成向文件内写内容都完成,这样不乱套了吗?
我现在没时间,一会给你按你的思路写一个正确的给你帖上。不过按你的思路径,循环完254个得半小时。

=========================================================

不允许重复回答呀!
以下是按你的想法写的,效率可能不高,因为循环254个网络连接本来就要消耗大量时间也不怪,用其它方法也快不到哪去!
帖在这的代码可复制粘帖后可以直接运行。

以下代码请写在一个模块内:监测调用的程序运行是否完成

Option Explicit
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Declare Function CloseHandle Lib "kernel32" (hObject As Long) As Boolean
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

Sub ShellAndWait(cmdline As String, xianshijiemian As Boolean)
Dim NameOfProc As PROCESS_INFORMATION
Dim NameStart As STARTUPINFO
Dim X As Long
If xianshijiemian = False Then
NameStart.wShowWindow = 0
NameStart.dwFlags = &H1
End If
NameStart.cb = Len(NameStart)
X = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, NameStart, NameOfProc)
X = WaitForSingleObject(NameOfProc.hProcess, INFINITE)
X = CloseHandle(NameOfProc.hProcess)
End Sub

以下内容写在你窗体的按钮中:

Private Sub Command1_Click()
Dim a As Integer, p As String
For a = 1 To 4
ShellAndWait "cmd /c ping 192.168.0." & a & ">c:\" & a & ".txt", False
DoEvents
Command1.Caption = "进行中(" & Trim(a) & ")"
DoEvents
Next a
Open "C:\0.TXT" For Output As #1
For a = 1 To 254
If Dir("C:\" & Trim(a) & ".TXT") <> "" Then
Open "C:\" & Trim(a) & ".TXT" For Input As #2
Do
If EOF(2) Then Exit Do
Line Input #2, p
Print #1, p
DoEvents
Loop
Close #2
Kill ("C:\" & Trim(a) & ".TXT")
End If
DoEvents
Next
Close #1
MsgBox "文件已生成,文件名为C:\0.TXT"
End Sub

Shell "cmd /c ping 192.168.0." & a & ">>c:\1.txt"
多了个>号
改成
Shell "cmd /c ping 192.168.0." & a & ">c:\1.txt"
试试

至于给分,你看帮助好了,在公司不能用QQ

qipinw,这样连续调用shell当然是254个CMD了,可以第一次shell其他的用sendkeys来模拟