Results 1 to 17 of 17

Thread: My Big Problem....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    My Big Problem....

    first i'd like to thank all persons who helped me in my project

    and i need someone help me to solve this

    i have two notepad files
    outfile.txt
    testoutfile.txt


    what i want to do is to insert some lines from outfile.txt to testoutfile.txt

    Explaination:
    start with outfile.txt insert every line in testoutfile.txt
    if you reach the word solution skip this line in outfile.txt and skip a line in testoutfile.txt then continue inserting
    do the same to the rest of lines

    i attached a samlpe file to the formating of the file i need sample.txt


    please help me
    Attached Files Attached Files

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: My Big Problem....

    Try this:
    VB Code:
    1. Dim DatNr1 as Integer
    2. Dim DatNr2 as Integer
    3. Dim strTextLine as String
    4. Dim ret as Integer
    5. DatNr1=FreeFile
    6. Open "outfile.txt" For Input as DatNr1
    7. DatNr2=FreeFile
    8. Open "testoutfile.txt" For OutPut as DatNr2
    9. Do While Not EOF (DatNr1)
    10.    Input #DatNr1,strTextLine
    11.  
    12.    ret= Instr(1,strTextLine,"solution")
    13.    If ret<>0 Then
    14.       Write #DatNr2, strTextLine
    15.    Else
    16.       Write #DatNr2,""
    17.    End If
    18. Loop
    Not tested!
    Close #DatNr1
    Close #DatNr2
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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

    Re: My Big Problem....

    i ran the code i still had that i did before, the result file is attached

    you must have changed the code slightly
    Attached Files Attached Files
    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: My Big Problem....

    Hi westconn1

    i don't know why the code you wrote didn't work for me
    i just changed the directories
    i'm very upset

    i don't know what to do????

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: My Big Problem....

    opus this is what i got from your code
    Attached Files Attached Files

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: My Big Problem....

    westconn1
    i run the code again
    this is what i got

    (subscript out of rang)
    points to this line in getnext function

    ReDim Preserve arrb(i - strt - 1)

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: My Big Problem....

    I see the mistake.
    Use this:
    VB Code:
    1. Dim DatNr1 As Integer
    2.     Dim DatNr2 As Integer
    3.     Dim strTextLine As String
    4.     Dim ret As Integer
    5.     DatNr1 = FreeFile
    6.     Open "outfile.txt" For Input As DatNr1
    7.     DatNr2 = FreeFile
    8.     Open "testoutfile.txt" For Output As DatNr2
    9.     Do While Not EOF(DatNr1)
    10.        Input #DatNr1, strTextLine
    11.  
    12.        ret = InStr(1, LCase(strTextLine), "solution")
    13.        If ret <> 0 Then
    14.           Write #DatNr2, strTextLine
    15.        Else
    16.           Write #DatNr2,
    17.        End If
    18.     Loop
    19.     Close #DatNr1
    20.     Close #DatNr2

    As I understood the task is that you want all the lines from outfile.txt exemt those that contain the word "solution", instead of those you want a empty line. However your sample.txt is looking like the outfile.txt!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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

    Re: My Big Problem....

    the last code i posted in the previous thread no longer used the getnext function
    so you must be using an earlier version

    check here
    http://www.vbforums.com/showpost.php...6&postcount=22
    Last edited by westconn1; Nov 28th, 2006 at 06:25 AM.
    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

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: My Big Problem....

    opus this time the file testoutfile.txt is empty!

    westconn1 i tried this code
    i got the same output in case of few word
    and an error pointing to this line in case of paragraphs
    (subscript out of range)
    VB Code:
    1. Print #f1, Mid(arrsecond(i), 1, pos); arrfirst(j); Mid(arrsecond(i), pos1, Len(arrsecond(i)) - pos1 + 1) ' print the line to file, with replacement

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

    Re: My Big Problem....

    try it with the same files i was usng, these are the files i was using to write the code, the files of course came from you to start with, and process with no errors


    a subscript out of range error means that one of the arrays has gone past its end, check to number of elements in each array, if the number of repacements is not enough for the number of strings to be replaced, you will get that error
    Attached Files Attached Files
    Last edited by westconn1; Nov 28th, 2006 at 07:30 AM.
    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

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 2006
    Posts
    131

    Re: My Big Problem....

    westconn1
    this is the output from your attached files



    why???
    Attached Files Attached Files

  12. #12
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: My Big Problem....

    I Have no idea why the testoutfile.txt should be empty.
    There is a mistake in the code, it uses all lines with "solution" imnstead of those without.

    I changed it:
    VB Code:
    1. Dim DatNr1 As Integer
    2.     Dim DatNr2 As Integer
    3.     Dim strTextLine As String
    4.     Dim ret As Integer
    5.     DatNr1 = FreeFile
    6.     Open "outfile.txt" For Input As DatNr1
    7.     DatNr2 = FreeFile
    8.     Open "testoutfile.txt" For Output As DatNr2
    9.     Do While Not EOF(DatNr1)
    10.        Input #DatNr1, strTextLine
    11.  
    12.        ret = InStr(1, LCase(strTextLine), "solution")
    13.        If ret = 0 Then
    14.           Write #DatNr2, strTextLine
    15.        Else
    16.           Write #DatNr2,
    17.        End If
    18.     Loop
    19.     Close #DatNr1
    20.     Close #DatNr2

    the resulting file I get when using your "outfile.txt" is attached!
    Last edited by opus; Jul 18th, 2007 at 02:53 AM.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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

    Re: My Big Problem....

    can you post the exact code you are using, or better still your project and i will see if i can see why you are getting different result

    i make a new project, copy and paste the code into it, under a command button, presto, this file

    i have made no changes to the code at all, so i can not say why it is not working for you
    Attached Files Attached Files
    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

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

    Re: My Big Problem....

    opus, you need to have the output file contain the arabic words that are in the original file, if you just print to file the arabic is translated unless you use ucode marker in the file,
    as you have not opened the file with the arabic words for reading i don't see how this can work at all, though maybe i am missing something
    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

  15. #15
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: My Big Problem....

    Good morning westconn1

    Maybe I don't get it,but I was only answering the question from this threat:

    what i want to do is to insert some lines from outfile.txt to testoutfile.txt

    Explaination:
    start with outfile.txt insert every line in testoutfile.txt
    if you reach the word solution skip this line in outfile.txt and skip a line in testoutfile.txt then continue inserting
    do the same to the rest of lines

    Now that I looked into that other threat, it seems to me, this question doesn't give to whole picture!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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

    Re: My Big Problem....

    Now that I looked into that other threat, it seems to me, this question doesn't give to whole picture!
    quite right
    the suggestion here was to replace the whole line from one file with the line from the other, the original thread was to just replace a single word from a second file into the brackets in the first file, this was initially simple, except the arabic did not save in the text file, but converted into (f....??) or some such thing,

    if you feel so inclined, test my code posted at the end of the other thread with the input files posted in #10 here, to see if you get the correct output, i originally wrote the code in VBA so just in case that was a problem did a new project today in vb and it all worked fine again, but as om is still having a problem it would be good if someone else can test it too

    regards
    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

  17. #17
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: My Big Problem....

    I'd guess I will see your result, probably has something to with the language settings.
    Will look into it, if I find time.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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