Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:55:24+00:00 2026-06-17T09:55:24+00:00

I’m trying to read a text file that has 1147 lines. The code below

  • 0

I’m trying to read a text file that has 1147 lines. The code below is only reading lines 1050-1147. My goal is to read the entire file and pull out the specific values located on various lines to use within a script. An example would be the value 2 from the line containing “BlockList: 2”. I’ve included a snippet of the format of the text file as it’s formatted differently than any example that I’ve come across (lines 1116-1128); The values I’m trying to access are indented the same as the first line shown (not sure if that matters).

    fixation.OffsetTime: 426611
    *** LogFrame End ***
Level: 2
*** LogFrame Start ***
Procedure: TestProc
BlockList: 2
BlockList.Cycle: 1
BlockList.Sample: 2
Running: BlockList
*** LogFrame End ***

Level: 1
* LogFrame Start *
Experiment: ChoiceofLotteries_fMRI_I

The code so far:

Sub OpenTextFileTest()
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Dim fs, f, contents, var1
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("C:\NameOfFile.txt", 1)
    contents = f.ReadAll
    f.Close
    Debug.Print contents
End Sub

Does anyone have any suggestions how to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:55:25+00:00Added an answer on June 17, 2026 at 9:55 am

    Try this (An example on how to extract the value of BlockList:)

    Sub Sample()
        Dim MyData As String, strData() As String
        Dim i As Long
    
        '~~> Replace this with the relevant file
        Open "C:\NameOfFile.txt" For Binary As #1
        MyData = Space$(LOF(1))
        Get #1, , MyData
        Close #1
        strData() = Split(MyData, vbCrLf)
    
        For i = LBound(strData) To UBound(strData)
            If InStr(1, strData(i), "BlockList:", vbTextCompare) Then
                Debug.Print Split(strData(i), ":")(1)
                Exit For
            End If
        Next i
    End Sub
    

    FOLLOWUP

    The Text file that you have is Unicode text File and hence you are getting that problem. If you do a SaveAs and then select ANSI in the encoding and then run the above code, does it work?

    Click here For an alternative way of reading txt files using VBA

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read in a text input file that contains a list
I have a gzipped text file that I'm trying to read within PHP (using
I am trying to read values from a text file using the Qt code
I'm trying to parse a text file that has a heading and the body.
I am trying to read a file type that has a mixture of integers,
I'm trying to read a text file but before that I want to know
I'm trying to use urllib and urllib2 to read from a text file that
I am trying to read in a file that has HTML list items with
I'm trying to read existing xml file, that has duplicated namespace declarations. It is
I'm trying to read a text file using a synchronous request. It doesn't work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.