Results 1 to 2 of 2

Thread: Is it possible to read a file to a string

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Ede, Gelderland, Nederland
    Posts
    26

    Arrow

    Is it possible to do that fast, not this way:

    Code:
        FreeF = FreeFile
        
        Open txtFile For Binary Access Read As #FreeF
            
            lstChat.AddItem "Bezig met inlezen van bestand...", 0
            ws(0).SendData "Chat: " & "Bezig met inlezen van bestand..."
            
            strFD = "": strFD1 = "": strFD2 = "": strFD3 = "": strFD4 = "": lngGelezen = 0
            strFD5 = "": strFD6 = "": strFD7 = "": strFD8 = ""
            Dim strDATA_65000 As String * 65000
            Dim strDATA_30000 As String * 30000
            Dim strDATA_10000 As String * 10000
            Dim strDATA_1000 As String * 1000
            Dim strDATA_100 As String * 100
            Dim strDATA_10 As String * 10
            Dim strDATA_1 As String * 1
            Dim lLF As Long
            pgStatus(8).Visible = True
            pgStatus(8).Max = LOF(FreeF)
            lLF = LOF(FreeF)
            
            If lLF >= 65000 Then
                Do
                    Get #FreeF, , strDATA_65000
                    strFD = strFD & strDATA_65000
                    lngGelezen = lngGelezen + 65000
                    If lLF - lngGelezen < 65000 Then Exit Do
                    DoEvents
                Loop
            End If
            If lLF - lngGelezen >= 30000 Then
                Do
                    Get #FreeF, , strDATA_30000
                    strFD = strFD & strDATA_30000
                    lngGelezen = lngGelezen + 30000
                    If lLF - lngGelezen < 30000 Then Exit Do
                    DoEvents
                Loop
            End If
            If lLF - lngGelezen >= 10000 Then
                Do
                    Get #FreeF, , strDATA_10000
                    strFD = strFD & strDATA_10000
                    lngGelezen = lngGelezen + 10000
                    If lLF - lngGelezen < 10000 Then Exit Do
                    DoEvents
                Loop
            End If
            If lLF - lngGelezen >= 1000 Then
                Do
                    Get #FreeF, , strDATA_1000
                    strFD = strFD & strDATA_1000
                    lngGelezen = lngGelezen + 1000
                    If lLF - lngGelezen < 1000 Then Exit Do
                    DoEvents
                Loop
            End If
            If lLF - lngGelezen >= 100 Then
                Do
                    Get #FreeF, , strDATA_100
                    strFD = strFD & strDATA_100
                    lngGelezen = lngGelezen + 100
                    If lLF - lngGelezen < 100 Then Exit Do
                    DoEvents
                Loop
            End If
            If lLF - lngGelezen >= 10 Then
                Do
                    Get #FreeF, , strDATA_10
                    strFD = strFD & strDATA_10
                    lngGelezen = lngGelezen + 10
                    If lLF - lngGelezen < 10 Then Exit Do
                    DoEvents
                Loop
            End If
            If lLF - lngGelezen >= 1 Then
                Do
                    Get #FreeF, , strDATA_1
                    strFD = strFD & strDATA_1
                    lngGelezen = lngGelezen + 1
                    If lLF - lngGelezen < 1 Then Exit Do
                    DoEvents
                Loop
            End If
    Thanks

    Please replay!
    LauPro

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    [
    Code:
    'read the complete file into a string
    
    Option Explicit
    
    Private Sub Command1_Click()
    
        Dim sfile As String, intNum As Integer
        Dim myString as string
    
        intNum = FreeFile
        sfile = "C:\my Documents\myfile.txt"
        
        Open sfile For Input As intNum
          myString = StrConv(InputB(LOF(intNum), intNum), vbUnicode)
         Close intNum
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width