Article View: be.comp.programming
Article #15601Re: newbie Q: lezen txt file in vb
From: Briachons
Date: Mon, 11 Sep 2000 16:23
Date: Mon, 11 Sep 2000 16:23
52 lines
2917 bytes
2917 bytes
On Mon, 11 Sep 2000 15:58:50 GMT, ViperRT10 wrote:
> het lukt me maar niet om van txt files te lezen met vb (6.0) wil iemand een
> stukje code posten met een werkende code?
Onderstaand stukje opent een file (Welke file? Strpath) en leest het
helemaal in, op zoek naar een bepaalde letter.(strLimiter)
Dit is VB 6 code, en ik gebruik het Filesystem-object. (Zie help
daarvoor)
-------- CODE HIERONDER --------
strPath = "c:\temp\outp.txt"
strLimiter = "%"
' open file
' creating the filesystem object
Set fs = CreateObject("Scripting.FileSystemObject")
' open inputfile
Set InputFile = fs.GetFile(strPath)
strInputFile = InputFile.OpenAsTextStream(cReading, ->
cDefault).readall
If Len(strInputFile) = 0 Then
Call MsgBox("The Quote-file is empty!!!", vbOKOnly + ->
vbCritical)
Exit Function
End If
lPosition = 1
Do Until lPosition >= Len(strInputFile)
strTemp = Mid(strInputFile, lPosition, 1)
If strTemp = strLimiter Then
lQuoteCount = lQuoteCount + 1
End If
lPosition = lPosition + 1
Loop
dblAverageLenght = Len(strInputFile) / lQuoteCount
' Displaying the results & update registry
Call MsgBox("I found " & lQuoteCount & " quotes." & vbCr & vbLf &
"The average lenght is " & CInt(dblAverageLenght) & " bytes",
vbOKOnly, "Results...")
bRegUpdate = MsgBox("Do you want to update the registry with this
setting?", vbQuestion + vbYesNo, "Update ini?")
If bRegUpdate = 6 Then ' Yes
Call SaveSetting(App.EXEName, "MAIN", "QUOTELENGHT",
CStr(CLng(dblAverageLenght)))
End If
--
briachons.WHISKEY@yahoo.com > but don't drink and mail
http://pandorafaq.webhop.net/ > F.A.Q.-nieuwsgroepen
http://briachons.50megs.com/ > Eigen homesite
[op het einde van mijn limiet heb ik nog een stukje maand over]
Technical Details
Message-ID:
<nd1qrs42tdokba5d3t1hfqu9g8qba9elg8@4ax.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!10.10.220.74.MISMATCH!sn-xit-05!supernews.com!newsfeed.online.be!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mailReferences:
<_i7v5.320638$DJ4.4735819@afrodite.telenet-ops.be>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcea4,b62e0395e5517584 X-Google-Attributes: gidfcea4,public X-Google-ArrivalTime: 2000-09-11 09:24:58 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!10.10.220.74.MISMATCH!sn-xit-05!supernews.com!newsfeed.online.be!newsfeeds.belnet.be!news.belnet.be!afrodite.telenet-ops.be!not-for-mail From: Briachons <briachons.WHISKEY@yahoo.com> Newsgroups: be.comp.programming Subject: Re: newbie Q: lezen txt file in vb Organization: Briachons inc Message-ID: <nd1qrs42tdokba5d3t1hfqu9g8qba9elg8@4ax.com> References: <_i7v5.320638$DJ4.4735819@afrodite.telenet-ops.be> X-Newsreader: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 53 Date: Mon, 11 Sep 2000 16:23:01 GMT NNTP-Posting-Host: 213.224.85.11 X-Trace: afrodite.telenet-ops.be 968689381 213.224.85.11 (Mon, 11 Sep 2000 18:23:01 MET DST) NNTP-Posting-Date: Mon, 11 Sep 2000 18:23:01 MET DST