CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2003
    Posts
    322

    [RESOLVED]Not using VB6 for 1.5 years has made me weak

    I'm trying to remember how to read in a text file, without using the FSO's.

    This is actually for an Excel VBA macro, and I don't want to have to install the anything on the user's system, other can copying an Excel file.

    I'm able to open the file and read all of the test names in just fine.

    The file basically looks like this

    Test1
    Test2
    Test3


    Those names are actually much longer and proprietary, but these will do for the example.


    This is what I've started with, but it's not working.

    List of tests looks like this "test1 test2 test3"
    each test name is separated by a vbCr

    Code:
    Private Sub SeparateTestnames(listofTests As String)
    
    Dim newtest As clsTestDescription
    Dim curTest As String
    Dim startLoc As Long
    Dim endLoc As Long
    
       curTest = ""
    
       startLoc = 1
    
       Do
           endLoc = InStr(startLoc, listofTests, vbCr, vbTextCompare)
           Set newtest = New clsTestDescription
           curTest = LTrim(Mid$(listofTests, startLoc, endLoc))
           newtest.letTestname = curTest
           colAlltests.Add newtest  '  this collection is defined in class initialize
           startLoc = endLoc + 1
    
       Loop Until (startLoc >= Len(listofTests))
    
    
    End Sub
    The call to Mid$ is returning Test1 Test2
    on the same line.

    I want to parse each test name separately, then stick one test name into the class, and that class into a collection.

    Am I very far off?
    thanks
    Last edited by cappy2112; July 2nd, 2007 at 03:33 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Not using VB6 for 1.5 years has made me week

    Load the file, and then SPLIT() it up.

    This should give you some ideas. It splits the file on chr(13), and then adds two vbcrlf's for each one.
    Attached Files Attached Files
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2004
    Location
    LA. California Raiders #1 AKA: Gangsta Yoda™
    Posts
    616

    Re: Not using VB6 for 1.5 years has made me week

    Do not use FSO as it requires a dependancy file to be distributed with your workbook/app.

    Use dglienna's example to read in a text file with no dependancies if all done within VBA
    VB/Office Guru™ (AKA: Gangsta Yoda™)
    VB Forums - Super Moderator 2001-Present

    Microsoft MVP 2006-2011

    Please use [code]your code goes in here[/code] tags when posting code.

    Senior Software Engineer MCP, BSEE, CET
    VS 2012 Premium, VS 6.0 Enterprise SP6, VSTO, Office Ultimate 2010, Windows 7 Ultimate
    Star Wars Gangsta Rap SE Reputations & Rating Posts Office Primary Interop AssembliesAdvanced VB/Office Guru™ Word SpellChecker™.NETAdvanced VB/Office Guru™ Word SpellChecker™ VB6Outlook Global Address ListVB6/Crystal Report Ex.VB6/CR Print Setup Dialog Ex.

  4. #4
    Join Date
    Apr 2003
    Posts
    322

    Re: Not using VB6 for 1.5 years has made me weak

    Quote Originally Posted by dglienna
    Load the file, and then SPLIT() it up.

    This should give you some ideas. It splits the file on chr(13), and then adds two vbcrlf's for each one.

    OH YES, Splittttttttttttttt()!. It's all coming back, slowly now ;-)

    I use split almost daily, when I code in Python


    Thanks for the memories :-)

  5. #5
    Join Date
    Apr 2003
    Posts
    322

    Re: Not using VB6 for 1.5 years has made me week

    Quote Originally Posted by dglienna
    Load the file, and then SPLIT() it up.

    This should give you some ideas. It splits the file on chr(13), and then adds two vbcrlf's for each one.

    This works great. Just finished implementing it

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