CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2012
    Posts
    20

    text file content into vb 6.0 variable

    how to get the contents of a text file into a variable in vb 6.0?
    any help?

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: text file content into vb 6.0 variable

    You ned to Open the file for reading and store its contents into the variable :

    Something like ;

    Code:
    Dim FileName1 As String 'holds first file path
    
    Dim FileH1 As Integer 'file handle 1
    
    Dim strInOut As String 'holds input 
    
    FileName1 = "E:\Test.txt" 'path to 1st file
    
    Open FileName1 For Binary Access Read As #FileH1 'open file
    'read the info line by line
     strInOut = Space$(LOF(1))
      Get #FileH1, , strInOut
    
    Close #FileH1 'close the handles

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: text file content into vb 6.0 variable

    You could also open it for input and use the Input # method to read the entire file into a variable.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Dec 2012
    Posts
    20

    Re: text file content into vb 6.0 variable

    thank you for your response...well i used this...it works...
    Code:
    Set ftxt = fs.CreateTextFile("D:\xxx\yy.txt", True) 
    textperl = "initialized text"
    Open "D:\xxx\yy.txt" For Input As #1
    While Not EOF(1)
    Input #1, MyData
    value = MyData
    somevariable = somevariable & vbNewLine & value
    Wend
    Debug.Print textperl
    Close #1
    Set ftxt = Nothing

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

Featured