Solved

VB6 string variable truncating data that it reads from a file

Posted on 2014-11-22
5
314 Views
Last Modified: 2014-11-24
Experts,

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
Loop
Len(strLine)

fsoStream.Close
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="http:someURL.com"></a>
<a title="some text" href="http://I want to extract this link.html" ></a> 
</td>

Open in new window


I am attaching the text file to this post.

Thanks!
temp.txt
0
Comment
Question by:Jay Balu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 47

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.
0
 
LVL 47

Accepted Solution

by:
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>
                    <ul>
                        <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>
                    </ul>
                </div>
                <div class="item">
                    <h4>GMAT Resources</h4>
                    <ul>
                        <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>                    
                    </ul>
                </div>
                <div class="item">
                    <h4>Partners</h4>
                    <ul>
                        <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>
                    </ul>
                </div>
                <div class="item">
                    <h4>MBA Resources</h4>
                    <ul>
                        <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>
                    </ul>
                </div>
                <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="http://deepinspire.com"><img src="/static/img/deep_logo.png" alt=""/></a>
                    <p>&copy; DeeP 2012<br/>
                    Web Design &amp; Development
                    </p>
                </div>
            </div>
            <div class="down">
                <a href="http://www.gmac.com/">www.gmac.com</a><span>|</span><a href="http://www.mba.com/">www.mba.com</a>
            </div>
        </div>
    </div><!-- / #footer -->

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

       <script type="text/javascript">
       // <![CDATA[
          if (window.reimg_version)
          {
             reimg_loading();
          }
       // ]]>
       </script>
    <!-- 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)']);
    _gaq.push(['_trackPageview']);

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

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

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

$(document).ready(function() {
    $(document).bind('click', function(e) {
        var target = (window.event) ? e.srcElement : e.target;
        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:\/\/gmatclub.com/, '') + '__/outgoing/' + link.replace(/:\/\//, '/');
    _gaq.push(['_trackPageview', link]);
    });
});
</script>

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

<script type="text/javascript">
$(document).ready(function() {
    $('#nav a').hover(
        function(e) {
      if (location.href.search("http://gmatclub.com/forum/") != -1) {
                var trackplace = 'Forum Pages - Menu Dropdown';
            }
      else if ( (location.href == "http://gmatclub.com/") || (location.href == "http://gmatclub.com/?fl=menu") ) {
                var trackplace = 'Home Page - Menu Dropdown';
            }
          else if (location.href.search("http://gmatclub.com/blog/") != -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;
        }
    );
});
</script>

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

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

<!-- 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>
        
        <script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
        </script>
        
        <noscript>
            <div style="display:inline;">
                <img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1071875456/?label=aJ2TCIyY-gEQgIuO_wM&amp;guid=ON&amp;script=0"/>
            </div>
        </noscript>

        </body>
</html>

Open in new window

0
 

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.
0
 
LVL 47

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
0
 

Author Comment

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

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28568498.html

Sorry, if I am hijacking this post.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…

737 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