Results 1 to 8 of 8

Thread: [RESOLVED] search untile empty line

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Resolved [RESOLVED] search untile empty line

    small Q1:
    how can i stop searching a .txt file if i reach an empty line?


    small Q2:
    if i got what i'm searching
    VB Code:
    1. If UCase(Left(tmp(x), 14)) = Text3.Text Then
    how can i add a char ,for example ">" in position 15 in the file


    Last edited by om-yousif; Nov 29th, 2006 at 03:19 PM.

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: search untile empty line

    Q1: what is the code you are using to search the .txt file...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: search untile empty line

    For question 1:
    VB Code:
    1. Private Sub Form_Load()
    2. Dim data As String
    3. Open "C:\test.txt" For Input As #1
    4.     Do While EOF(1) <> True
    5.         Line Input #1, data
    6.         If Len(Replace(data, " ", "")) = 0 Then Exit Do
    7.         Debug.Print data
    8.     Loop
    9. Close #1
    10. End Sub

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: search untile empty line

    @Rob123: you'd probably be better using Trim$ for that line:
    VB Code:
    1. If Len(Trim$(Data)) = 0 Then Exit Do

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: search untile empty line

    VB Code:
    1. If UCase(Left(tmp(x), 14)) = Text3.Text Then tmp(x) = left(tmp(x), 14) & ">" & mid(tmp(x), 15)
    the above should work if you want the whole string with > inserted at that position, if you just want the first part and the > then leave off the mid part
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: search untile empty line

    hi westconn1
    OK this code is adding the char to tmp(x)
    i checked that by this code
    VB Code:
    1. text1.text=tmp(x)

    now how it can be copied to the text file?

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: search untile empty line

    assuming the array tmp is a split of the file you opened and that you just want to overwrite it, then open the same (or other) file for output, join the array and print to file
    this is after all substitutions are done, so that you only write to file once

    VB Code:
    1. Open myfile For Output As 1
    2. Print #1, Join(tmp, vbNewLine)
    3. Close 1
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: search untile empty line

    thanks alot westconn1
    i've done 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