VB6 string variable truncating data that it reads from a file

Posted on 2014-11-22
Last Modified: 2014-11-24

I have two questions
1. When I am reading a 600kb text file (HTML code) into a string variable, it is truncating pretty much half of the content. Here is the code I have... where am I going wrong?
Dim fso As New FileSystemObject
Dim f As File
Dim fsoStream As TextStream
Dim strLine As String
Set f = fso.GetFile("C:\Users\Neanderthal\Desktop\MyProj\GMATClubLog.txt")
Set fsoStream = f.OpenAsTextStream(ForReading)
' Read the file line by line, printing the results to the Form
Do While Not fsoStream.AtEndOfStream
     strLine = fsoStream.ReadLine
     Debug.Print strLine

Set fsoStream = Nothing
Set f = Nothing
Set fso = Nothing

Open in new window

2. Basically why I want to read the whole content of the text file is because I want to extract a repeating set of data based on the search criteria . And this is the repeating code. How can I achieve this using vb 6 code?

<td class="topicsName" style="width:100%">
<a class="newestPostIcon" href=""></a>
<a title="some text" href="http://I want to extract this link.html" ></a> 

Open in new window

I am attaching the text file to this post.

Question by:Jay Balu
  • 3
  • 2
LVL 46

Expert Comment

by:Martin Liss
ID: 40459551
Take a look at the file in a text editor and see if there's anything unusual about the line following the last one that prints in the Immediate Window. It may be that there's something in the file that is being interpreted as EOF.
LVL 46

Accepted Solution

Martin Liss earned 500 total points
ID: 40460684
I interpreted your question as saying that you were not able to read all the lines, however after commenting out line 12 in your code above I was able to read the complete file. It just occurred to me however that when you say that "it is truncating pretty much half of the content"  that you might mean that individual lines are being truncated. If so can you tell me if any of the following (which is the end of the output from my implementation of your code) contain truncated lines?
                <div class="item">
                    <h4>Main navigation</h4>
                        <li><a href="/">Home</a></li>
                        <li><a href="/forum/">GMAT Forum</a></li>
                        <li><a href="/forum/gmat-prep-course-class-reviews-ratings-discount-codes-78451.html">GMAT Prep Courses</a></li>
                        <li><a href="/forum/2010-mba-rankings-99812.html">MBA Programs</a></li>
                        <li><a href="/forum/gmat-study-plan-for-gmat-novices-start-your-gmat-journey-80727.html">Self Prep</a></li>
                        <li><a href="/blog/category/blog/">GMAT Blog</a></li>
                        <li><a href="/blog/gmat-tests/">GMAT Test</a></li>
                        <li><a href="/wiki/GMAT">GMAT Wiki</a></li>
                        <li><a href="/">GMAT</a></li>
                        <li><a href="/chat/">Chat</a></li>
                        <li><a href="/blog/about-gmat-club/">About</a></li>
                        <li><a href="/blog/contact-us-2/">Contact</a></li>
                        <li><a href="/blog/partnerships-and-advertising-inquiries/">Advertise</a></li>
                <div class="item">
                    <h4>GMAT Resources</h4>
                        <li><a href="/forum/gmat-study-plan-for-gmat-novices-start-your-gmat-journey-80727.html">Build Your Study Plan</a></li>
                        <li><a href="/forum/gmat-faq-frequently-asked-questions-about-gmat-75809.html">GMAT Questions</a></li>
                        <li><a href="/forum/top-20-best-gmat-books-on-gmat-club-76582.html">Best GMAT Books</a></li>
                        <li><a href="/forum/all-gmat-cat-practice-tests-links-prices-reviews-77460.html">All the GMAT Tests</a></li>
                        <li><a href="/tests/">GMAT Club Tests</a></li>
                        <li><a href="/forum/gmat-test-dates-95067.html">Test Dates</a></li>
                        <li><a href="/forum/gmat-math-questions-and-intellectual-discussions-7/">GMAT Math</a></li>
                        <li><a href="/forum/verbal-gmat-questions-11/">GMAT Verbal</a></li>
                        <li><a href="/forum/competition-for-the-best-gmat-error-log-template-86232.html">Error Log Templates</a></li>
                        <li><a href="/forum/official-guide-for-gmat-12ed-in-complete-details-76806.html">GMAT Official Guide</a></li>
                        <li><a href="/gmat-score-calculator/">GMAT Score Calculator</a></li>                    
                <div class="item">
                        <li><a href="/blog/courses/e-gmat-discount-promotion-code/?fl=footer">e-GMAT</a></li>
                        <li><a href="/coupon-codes-and-discounts/the-economist-gmat-tutor-discount?fl=footer">Economist GMAT Tutor</a></li>
                        <li><a href="/blog/courses/kaplan-discount/?fl=footer">Kaplan</a></li>
                        <li><a href="/blog/courses/magoosh-gmat-discount/?fl=footer">Magoosh</a></li>
                        <li><a href="/blog/courses/gmat-pill-discount/?fl=footer">GMAT Pill</a></li>
                        <li><a href="/blog/courses/manhattan-gmat-discount/?fl=footer">Manhattan GMAT</a></li>
                        <li><a href="/blog/courses/optimus-prep-discount/?fl=footer">Optimus Prep</a></li>
                        <li><a href="/coupon-codes-and-discounts/princeton-review-gmat-discount-promotion-code?fl=footer">Princeton Review</a></li>
                        <li><a href="/blog/courses/veritas-prep-discount/?fl=footer">Veritas Prep</a></li>
                <div class="item">
                    <h4>MBA Resources</h4>
                        <li><a href="/forum/2010-mba-rankings-99812.html">Full Time MBA Rankings</a></li>
                        <li><a href="/forum/us-part-time-mba-rankings-class-profiles-and-comparison-84898.html">Part Time MBA Rankings</a></li>
                        <li><a href="/forum/international-schools-rankings-class-profiles-and-comparison-83394.html">International MBA Rankings</a></li>
                        <li><a href="/forum/best-app-tips-77803.html">Best App Tips</a></li>
                        <li><a href="/forum/best-mba-books-99173.html">Best MBA Books</a></li>
                        <li><a href="/forum/school-info-rankings-fit-visits-and-how-to-choose-58751.html">Application Reference</a></li>
                        <li><a href="/forum/mba-interview-tips-and-experiences-89455.html">Interviews</a></li>
                        <li><a href="/forum/best-resume-cv-format-template-tips-85627.html">Resumes</a></li>
                        <li><a href="/forum/admission-consultants-124/">Free Profile Evaluation</a></li>
                        <li><a href="/forum/why-mba-84855.html">Why MBA</a></li>
                <div class="item logo">
                    <a href="/"><img src="/static/img/gmat_logo.png" alt=""/></a>
                    <p>Copyright &copy; GMAT Club</p>
                    <p class="marginBottom">GMAT &reg; is a registered trademark of the Graduate Management Admission Council &reg; (GMAC &reg;). GMAT Club's website has not been reviewed or endorsed by GMAC.</p>
                    <a href=""><img src="/static/img/deep_logo.png" alt=""/></a>
                    <p>&copy; DeeP 2012<br/>
                    Web Design &amp; Development
            <div class="down">
                <a href=""></a><span>|</span><a href=""></a>
    </div><!-- / #footer -->

    <!-- END footer-new-forum.html -->

       <script type="text/javascript">
       // <![CDATA[
          if (window.reimg_version)
       // ]]>
    <!-- GA Content Groups MOD B -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-1891334-1']);
    _gaq.push(['_setPageGroup', '1', 'GMAT Problem Solving (PS)']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

<!-- GA Content Groups MOD E --><!-- Outbound link tracking -->

<script type="text/javascript">
function isLinkExternal(link) {
    var r = new RegExp('^https?://(?:www.)?' +^www./, ''));
        return !r.test(link);

$(document).ready(function() {
    $(document).bind('click', function(e) {
        var target = (window.event) ? e.srcElement :;
        while (target) {
            if (target.href) break;
            target = target.parentNode;
        if (!target || !isLinkExternal(target.href)) return true;
        var link = target.href;
    link = location.href.replace(/^http:\/\/, '') + '__/outgoing/' + link.replace(/:\/\//, '/');
    _gaq.push(['_trackPageview', link]);

<!-- Sending data to GA when top menu items are hovered -->

<script type="text/javascript">
$(document).ready(function() {
    $('#nav a').hover(
        function(e) {
      if ("") != -1) {
                var trackplace = 'Forum Pages - Menu Dropdown';
      else if ( (location.href == "") || (location.href == "") ) {
                var trackplace = 'Home Page - Menu Dropdown';
          else if ("") != -1) {
                var trackplace = 'Blog Pages - Menu Dropdown';
          else {
                var trackplace = 'Other Pages - Menu Dropdown';
          var cat = $(this).parent('li').parent('ul.sub-menu').prev().find('span').html();
          var label = $(this).find('span').html();
          if (!cat) {
              var tracklink = label;
          else {
              var tracklink = cat + ' -- ' + label;
          _gaq.push(['_trackEvent', trackplace, tracklink]);
        function() {
            return true;

<!-- Sending data to GA when Facebook Connect button is clicked -->

<script type="text/javascript">
$(document).ready(function() {
        function(e) {
          _gaq.push(['_trackEvent', 'Facebook Connect Button', 'click']);

<!-- discounts -->
<script type="text/javascript" src="/static/js/discount.js?2"></script>
    <!-- Google Code for General Forum Visitors Remarketing List -->
        <script type="text/javascript">
            /* <![CDATA[ */
            var google_conversion_id = 1071875456;
            var google_conversion_language = "en";
            var google_conversion_format = "3";
            var google_conversion_color = "666666";
            var google_conversion_label = "aJ2TCIyY-gEQgIuO_wM";
            var google_conversion_value = 0;
            /* ]]> */
        <script type="text/javascript" src="">
            <div style="display:inline;">
                <img height="1" width="1" style="border-style:none;" alt="" src=";guid=ON&amp;script=0"/>


Open in new window


Author Comment

by:Jay Balu
ID: 40462240
Martin Liss - Thanks for your response. I was in fact mistaken, What happened was when I tried to print it in the VB Immediate window, it was not printing completely (could there be a limit on how much contact can be printed in that window?). But when I wrote it back to a text file, it was printing everything there. So... false alarm. Thanks for your answer though.
LVL 46

Expert Comment

by:Martin Liss
ID: 40462433
The Immediate Window will show at most 199 lines.

You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014

Author Comment

by:Jay Balu
ID: 40462459
Would you be interested in taking a quick look at my other question too?

Sorry, if I am hijacking this post.

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question