Results 1 to 5 of 5

Thread: String Extraction *RESOLVED*

  1. #1

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186

    String Extraction *RESOLVED*

    Probably an easy question. Is there a way to store the first 8 characters of a text file into the first item in an array, the next 10 in the next item, the next 12 in the next item, 10 in the next, etc??
    Last edited by run_GMoney; Jan 22nd, 2004 at 10:06 AM.
    Place Your VBForums Ad Here

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Try this .........

    Make sure you place the data.txt in "C:\" drive
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim FilePath As String
    5.     Dim strData As String
    6.     Dim tmp As String
    7.    
    8.     FilePath = "C:\data.txt"
    9.    
    10.     If Dir(FilePath) <> "" Then
    11.         Open FilePath For Input As #1
    12.             Do While Not EOF(1)
    13.                 Input #1, tmp
    14.                 strData = strData & tmp
    15.             Loop
    16.         Close #1
    17.    
    18.    
    19.         Dim arrData(2) As String
    20.         'copy the first 8 char
    21.         arrData(0) = Mid(strData, 1, 8)
    22.        
    23.         'copy the next 10 char
    24.         arrData(1) = Mid(strData, 9, 12)
    25.        
    26.         'copy the next 12 char
    27.         arrData(2) = Mid(strData, 21, 10)
    28.        
    29.         MsgBox "First 8 char :" & arrData(0) & vbCrLf & "Next 12 char:" & arrData(1) & vbCrLf & "Next 10 char:" & arrData(2)
    30.     Else
    31.         MsgBox "File/Path not found"
    32.     End If
    33. End Sub
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    About the Dir function, it'll return a path (passing your test) if the path given it is a folder. You need to use the GetAttr function to get around this, though that will only matter very rarely. Just being thorough.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by jemidiah
    About the Dir function, it'll return a path (passing your test) if the path given it is a folder. You need to use the GetAttr function to get around this, though that will only matter very rarely. Just being thorough.
    Yep thanks, I am aware of that, i try not using Dir function. If i already have a reference to the Scripting runtime i tend to use FSO's FileExist method. The question was about string extraction so didnt wanna spend time doing validaion, i guess run_GMoney has already got it covered.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Danial - Thanks for the Mid solution. I've put it to good use.

    jemidiah - I'll be sure to address the Dir issue when I get to it. For now I'm just wrangling with the concepts of how this data is output from the original program so I can figure out how I want to input it into mine.
    Place Your VBForums Ad Here

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