Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Read #1 stops where?
Message
De
27/06/2000 11:49:38
 
 
À
22/06/2000 08:11:09
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00383078
Message ID:
00385133
Vues:
16
I am not sure how the Read# works as I have not used it. I wrote some code hoping that I could help you. The code below will read lines from a file (text or otherwise). I set it up using an array which makes it easier to count the number of lines.

Hope this helps:
' This code go in Form_Load for testing
' For testing purposes we will read AutoExecute
Open "C:\config.sys" For Input As #1

' Am array which will hold each line of our file
Dim Lines() As String
' Should our reading loop yeild to windows??
Dim bolYield As Boolean
' A number representing elements in lines() array
Dim intNumber As Long
' This variable will hold our files contents
Dim strFile As String

' We will calculate how long the method took
Dim lngTime As Long

' Should we let windows do something?
' (Yes for BIG files and yes by default)
bolYield = True

' This loop will read lines from our file into a
' string array
intNumber = 1

' Get the seconds since midnight
lngTime = Timer
Do Until EOF(1)
    ' Increase size of our array
    ReDim Preserve Lines(intNumber) As String
    
    ' Read one line from our file
    Line Input #1, Lines(intNumber)
    
    ' This variables holds our files contents
    strFile = strFile & vbNewLine & Lines(intNumber)
    
    ' Up number of lines by one
    intNumber = intNumber + 1
    
    ' Should we yeild
    If bolYield = True Then DoEvents
Loop

' Close our file
Close #1

' See how long it took
lngTime = Abs(Timer - lngTime)

' Display details about our file.
' Will display line number and contents
' of AutoExec.bat
MsgBox "Took: " & lngTime & " second(s)!" & vbNewLine & "Lines: " & _
                UBound(Lines) & vbNewLine & "(BOF)" & _
                strFile & vbNewLine & "(EOF)", vbOKOnly, _
                "File Data"
Kenneth Gilbert Jr, MCP
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform