🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #6913

Re: dosgegevens in een tekstveld in VB60

#6913
From: Wauters Kris
Date: Sat, 02 Nov 2002 12:06
90 lines
4269 bytes
>
> shell "nedstat > c:\file.txt"
> Vervolgens file.txt inlezen in de multilinetextbox ?
>
heu, ge gaat waarschijnlijk op die manier die file.txt al beginnen inlezen
alvorens die is aangemaakt.
(shell start dat commando op, en gaat terwijl al verder in VB)

dit is "ietsje" properder :

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long)
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 GetTempPath Lib "kernel32" Alias "GetTempPathA"
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32" Alias
"GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As
String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long

Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000

Private Const MAX_PATH = 260
Private Const CCHDEVICENAME = 32
Private Const CCHFORMNAME = 32
Private Const SRCCOPY = &HCC0020 ' (DWORD) destination = source

Public Sub ShellProgramAndWaitToFinish(StrPassedProgramToShell As String)

Dim LongiTask As Long, LongRet As Long, LongpHandle As Long

LongiTask = Shell(StrPassedProgramToShell, vbNormalFocus)
LongpHandle = OpenProcess(SYNCHRONIZE, False, LongiTask)
LongRet = WaitForSingleObject(LongpHandle, INFINITE)
LongRet = CloseHandle(LongpHandle)
If Err > 0 Then
  MsgBox CStr(Err.Number) & ":" & Err.Description & " " & ProgramToShell,
vbInformation, "ShellProgramAndWaitToFinish"
End If
End Sub

Public Function CreateTempFile() As String
    Dim StrTempDir As String
    Dim StrTmpFile As String
    Dim LongR As Long
    StrTempDir = Space$(MAX_PATH)
    LongR = GetTempPath(MAX_PATH, StrTempDir)
    StrTempDir = Left$(StrTempDir, LongR)
    StrTmpFile = Space$(MAX_PATH)
    LongR = GetTempFileName(StrTempDir, "TMP", 0, StrTmpFile)

    If LongR <> 0 Then
        StrTmpFile = Left$(StrTmpFile, InStr(StrTmpFile, Chr$(0)) - 1)
        CreateTempFile = StrTmpFile
    Else
      CreateTempFile = ""
    End If

End Function


als je bovenstaande code toevoegt in je applicatie, kan je dit doen:

dim StrTmpBestandsnaam as string
dim IntI as integer
dim StrTmpString as string

StrTmpBestandsnaam = CreateTempFile
ShellProgramAndWaitToFinish("ipconfig >" & StrTmpBestandsNaam)
IntI = FreeFile()
Open StrTmpBestandsNaam for input as #IntI
while not eof(IntI)
    textbox.text = textbox.text & line input#IntI,StrTmpString & VBCrLf
wend
close inti
kill StrTmpBestandsnaam

het cre�ren van een TempFile zorgt ervoor dat je geen fout krijgt als je
geen rechten zou hebben op de C-schijf ofzo,
(of als je windows op een D zou ge�nstalleerd zijn ofzo)
die ShellProgramAndWaitToFinish wacht tot het shell commando is uitgevoerd
en afgelopen alvorens terug verder te gaan met je VB applicatie.



Groeten,
Kris
Technical Details
Message-ID: <ydPw9.215$Nd.162@afrodite.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-04!supernews.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeed.icl.net!newsfeed.fjserv.net!skynet.be!skynet.be!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mail
References: <ylfw9.189256$8o4.30198@afrodite.telenet-ops.be> <zZDw9.191334$8o4.30186@afrodite.telenet-ops.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: fcea4,348945777d99e64d
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2002-11-02 04:10:19 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-04!supernews.com!newsfeed.news2me.com!newsfeed.media.kyoto-u.ac.jp!newsfeed.icl.net!newsfeed.fjserv.net!skynet.be!skynet.be!ossa.telenet-ops.be!afrodite.telenet-ops.be.POSTED!not-for-mail
From: "Wauters Kris" <wauters.kris@pandora.be>
Newsgroups: be.comp.programming
References: <ylfw9.189256$8o4.30198@afrodite.telenet-ops.be> <zZDw9.191334$8o4.30186@afrodite.telenet-ops.be>
Subject: Re: dosgegevens in een tekstveld in VB60
Lines: 92
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <ydPw9.215$Nd.162@afrodite.telenet-ops.be>
Date: Sat, 02 Nov 2002 12:06:54 GMT
NNTP-Posting-Host: 213.224.60.70
X-Complaints-To: abuse@telenet.be
X-Trace: afrodite.telenet-ops.be 1036238814 213.224.60.70 (Sat, 02 Nov 2002 13:06:54 MET)
NNTP-Posting-Date: Sat, 02 Nov 2002 13:06:54 MET
Organization: Telenet Internet