AllExperts > Visual Basic 
Search      
Visual Basic
Volunteer
Answers to thousands of questions
 Home · More Visual Basic Questions · Answer Library  · Encyclopedia ·
More Visual Basic Answers
Question Library

Ask a question about Visual Basic
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Aaron Young
Expertise
I have 11 Years of Programming Experience, 4 years with Visual Basic, I currently work as an Analyst Programmer for Red Wing Business Systems, Inc. I enjoy helping others out when they get stuck and have spent a lot of time in other Forums like VB-World and CodeGuru answering a lot of questions. I have a good knowlegde of VB overall, so will attempt any Question on any part of the Language, from Database Access to ActiveX Control Creation and all the Grey Fuzzy stuff in between. (I do enjoy using the APIs for Subclassing and getting that last drop of functionality out of VB).

 
   

You are here:  Experts > Computing/Technology > Basic > Visual Basic > Hey Aaron, I asked a question...

Visual Basic - Hey Aaron, I asked a question...


Expert: Aaron Young - 5/26/2005

Question
Hey Aaron,

I asked a question at VBForums, and instead of
typing it again, here is the link...

http://www.vbforums.com/showthread.php?p=2027435#post2027435

I hope you can help me, as this is driving me crazy!

Thanks,
Ron

Answer
Try:

'-------------------------------------------------------
Private Function SplitEx(ByVal sString As String, Optional ByVal sDelim As String = " ") As Variant
   Dim sItem As String
   Dim sList() As String
   Dim lChar As Long
   Dim lCount As Long
   
   Do
     ' Reset Split for non-Quoted Values
     lChar = InStr(sString, sDelim)
       
     If lChar > 0 Then
         ' Extract the Item from the String
         sItem = Left(sString, lChar - 1)
         ' Remove Item from the Remaining String
         sString = Mid(sString, lChar + Len(sDelim))
     Else
         ' Remaining String, becomes final Item
         sItem = sString
         sString = ""
     End If
       
     ' If something was extracted, add it to the Array
     If Len(sItem) > 0 Then
         ReDim Preserve sList(lCount)
         sList(lCount) = sItem
         lCount = lCount + 1
     End If
       
   ' Continue until no more delimiters are found.
   Loop While lChar > 0
   
   ' If there were items, return the array
   If lCount > 0 Then
       SplitEx = sList
   Else
       ' Otherwise return an empty array
       SplitEx = Array()
   End If
End Function

Private Sub Command1_Click()
  Dim intFree As Integer
  Dim strReadText As String
  Dim strTextLines() As String
  
  intFree = FreeFile
  Open "C:\SomeFile.txt" For Binary As #intFree
      strReadText = Space$(LOF(intFree))
      Get #intFree, , strReadText
  Close #intFree
  
  ' Create array of text lines from the file...
  strTextLines = SplitEx(strReadText, vbNewLine)
  
  Text1.Text = strTextLines(0) ' First line...
  Text2.Text = strTextLines(1) ' Second line...
End Sub
'-------------------------------------------------------

Regards,

- Aaron.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.