Home > Software engineering >  Vb to read TXT file
Vb to read TXT file

Time:09-30

Open "C: \ tmp1. TXT" For Input As # 1
The Do While Not EOF (1)
The Line Input # 1, Find_FileName11
N=N + 1
Loop
Close # 1
Label1=N

What was supposed to be 839 N

On my XP computer, the result of N will change constantly, there are 12,2,58,... And the results

But in my Windows 7 systems, a value of 839, is this why???????

CodePudding user response:


The Shell "CMD/c dir" & amp; P_Setting_Path & amp; "/s/b/a & gt; & gt;" & P_Tmp_PathName, vbHide
P_Setting_Path="search diploma folder"
P_Tmp_PathName="generated TXT file name"

In fact is the problem that the above statement, it on XP system, not read all of the file name after regeneration into TXT file, but read the part of the file name after the deposit, so the read data can increase slowly, in the end will read all the files,
To solve above problems, how to solve?

CodePudding user response:

 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long

Private Const STILL_ACTIVE As Long=& amp; H103
Private Const PROCESS_QUERY_INFORMATION As Long=& amp; H400

Private Sub Command1_Click ()
Dim pID As Long
Dim hProcess As Long
Dim lpExitCode As Long

'pID=Shell (" C: \ program. Exe, "vbNormalFocus)
PID=Shell (" d: \ Windows \ system32 \ notepad exe ", vbNormalFocus)
HProcess=OpenProcess (PROCESS_QUERY_INFORMATION, 0, pID)
'the following end waiting for the called process
The Do While True
Call Sleep (100) 'the words used to release during waiting for CPU resources
Call GetExitCodeProcess (hProcess, lpExitCode)
If lpExitCode & lt;> STILL_ACTIVE Then
The CloseHandle (hProcess)
The Exit Do
End the If
DoEvents' this sentence to ensure that the main application window drawing
Loop
MsgBox "invoked process runs over!"
End Sub
  • Related