i need help comparing text from a text file, to string

in an attempt to prevent replication...

Page 1 of 1

9 Replies - 1104 Views - Last Post: 04 June 2010 - 11:06 PM Rate Topic: -----

#1 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

i need help comparing text from a text file, to string

Posted 01 June 2010 - 01:22 AM

Dear Friends,

I am in need of assistance, I have just about pulled out my hair on this one, and don't know what I can do next to make this work.
I am currently writing programs that require very little maintenance, so that I don't have to issue updates... anyway to do this I use a flat file database, which when it works is beautiful, however, I am having issues with my code replicating the same items in the text file... in an attempt to catch the error I found myself in some trouble...

I have attempted to use loops and for...next statements and have got no where.

This is my current code. It crashes so be careful... no errors per say, just never ending loops...

'more fun with file creations:
' I have to open the two files and set them to variables to prevent duplicates...
Dim worker7 As String, worker8 As String, jim3 As Long, jim4 As Long
jim3 = 0
jim4 = 0
Open path0 & "\Phfle.dll" For Input As #10
    Do While Not EOF(10)
        Line Input #10, worker7
        If worker7 = year Then
            jim3 = jim3 + 1 ' hopefully this will help create a barrior if jim3 >0 then fail, else, will write to file
        End If
        MsgBox worker7 & " " & jim3
    Loop
Close #10
'create a file for use in opening up certain years and files... this is needed for say we want to look at past years times and placements
    If jim3 <= 0 Then
        Dim pth As Object
        Set pth = CreateObject("scripting.filesystemobject")
        If pth.FileExists(path0 & "\Pthfle.dll") Then
            Open path0 & "\Pthfle.dll" For Append As #144
                Print #144, year
            Close #144
        Else
            Open path0 & "\Pthfle.dll" For Output As #144
                Print #144, year
            Close #144
        End If
    End If
'end year path...
Open path0 & "\" & path1 & "\Pthfle.dll" For Input As #11
     Do While Not EOF(11)
        Line Input #11, worker8
        If worker8 = jim2 Then
            jim4 = jim4 + 1
        End If
        MsgBox worker8 & " " & jim4
     Loop
Close #11
'create a file for use in opening up certain months and files... this is needed for say we want to look at past years times and placements
    If jim4 <= 0 Then
        Dim moth As Object
        Set moth = CreateObject("scripting.filesystemobject")
        If moth.FileExists(path0 & "\" & path1 & "\Pthfle.dll") Then
            Open path0 & "\" & path1 & "\Pthfle.dll" For Append As #145
                Print #145, jim2
            Close #145
        Else
            Open path0 & "\" & path1 & "\Pthfle.dll" For Output As #145
                Print #145, jim2
            Close #145
        End If
    End If
'end month path


The code will not complete the task, the message boxes were to see if it was collecting line inputs from the files that I need to check against. I am almost positive that it is something stupid that I did... Please help me find it... or shoot me ...

Jesse Fender

Is This A Good Question/Topic? 0
  • +

Replies To: i need help comparing text from a text file, to string

#2 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: i need help comparing text from a text file, to string

Posted 01 June 2010 - 01:50 AM

check out this link

http://www.dreaminco...quential-files/

you will find your problem surely
Was This Post Helpful? 0
  • +
  • -

#3 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: i need help comparing text from a text file, to string

Posted 01 June 2010 - 09:13 AM

While your suggestion was good, I am still having an issue that the tutorial hasn't shown me.
the task i am trying to get done with the code I provided this morning was this:
1. check if the file exists, if it does then open it and pull each line of text from it and save it to a var in this case 'worker#'
2. check that var against one of the input fields var's so that the program will catch duplicate entries and move on with out writing to the file.
3. if the variables don't match then write to the file and move on.
the reason for this is so that I don't have to set up hard coded links to the files, as this would make things more complex and unstable. since the program is really something that i want to have very small and build it's self up to the point where users can customize the program to fit them. and reduce as much as possible the need for updates.

however when I try to get #1 to work it enters into a endless loop. or if i use the for...next statement, nothing... the variable that I need to get into the program isn't being pulled. This either causes the file to not be written, or to add an infinite loop of the text that I am trying to check for...

I am at a complete loss, I have a pretty good idea that it has been done before but I don't know how to get mine to work... I figured that i was doing something wrong, so I slept on it and it's not popping out at me, and its now a drive to find how to make this work.

changes in cove include while...wend from do while not...loop and added quotes over the catch vars check value, with no change.
changed jim3 & 4 to boolean, added a check if file exists and it works sometimes, but second time through it sets jim3 and 4 to false, which is where the never ending loop starts.
I am beginning to want to write the file to a list box or text box and comparing them from there...

Jesse Fender

This post has been edited by chuckjessup: 01 June 2010 - 09:35 AM

Was This Post Helpful? 0
  • +
  • -

#4 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: i need help comparing text from a text file, to string

Posted 01 June 2010 - 05:09 PM

I think I figured the issue... I was opening too many files for the program could handle per event. However I have run into a bit of a snag, and am asking for some advice. my code is below, I moved it from the command1_click() to a new command button that will be pressed in code... but there is an issue with the files being opened to close to each other, and thus i get an error 55, which is that the file isn't closed when windows attempts to open the file again. as you can probably tell I am not the most advanced coder, but this is making me feel really stupid. Is there a way to cause the program to wait before continuing the code, with out halting the application (which will not help me...) i saw something for .net but I hate .net... and would rather do anything else but deal with that kind of code.

Private Sub Command2_Click()
'a second attempt at the setting settings apart.
Dim wkr As Object, wkr2 As Object
Dim worker7 As String, worker8 As String, worker9 As String, wkr3 As String, year As String
Dim x As Long, I As Long, y As Long
If Option1.Value = True Then
    year = Mid(dte, 8, 4)
ElseIf Option2.Value = True Then
    year = Combo2.Text
End If
worker9 = year
    'reading how many lines are in the file.
    Set wkr2 = CreateObject("scripting.filesystemobject")
If wkr2.FileExists(App.Path & "\User\" & Label2.Caption & "\Pthfle.dll") Then
    Open App.Path & "\User\" & Label2.Caption & "\Pthfle.dll" For Input As #45
        Do Until EOF(45)
            Line Input #45, wkr3
            y = y + 1
            Combo8.AddItem wkr3
        Loop
    Close #45
   MsgBox y
End If  

'The break starts here, this is where i need the pause!
'even a half a second or so ...

Set wkr = CreateObject("scripting.filesystemobject")
If wkr.FileExists(App.Path & "\User\" & Label2.Caption & "\Pthfle.dll") Then
    Open App.Path & "\User\" & Label2.Caption & "\Pthfle.dll" For Input As #23
    For I = 1 To y
        Line Input #23, worker7
        If worker9 <> worker7 Then
        Combo7.AddItem worker7
        'create a file for use in opening up certain years and files... this is needed for say we want to look at past years tiimes and placements
        Dim pth As Object
        Set pth = CreateObject("scripting.filesystemobject")
        If pth.FileExists(App.Path & "\User\" & Label2.Caption & "\Pthfle.dll") Then
            Open App.Path & "\User\" & Label2.Caption & "\Pthfle.dll" For Append As #144
                Print #144, year
            Close #144
        Else
            Open App.Path & "\User\" & Label2.Caption & "\Pthfle.dll" For Output As #144
                Print #144, year
            Close #144
        End If
        Else
        'i dont want a loop it will fail!
        End If
    Next I
Close #23
End If
'end year path...
End Sub



Other that that it works...
:helpsmilie: I need like less than a second. all I need... :helpsmilie:

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#5 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: i need help comparing text from a text file, to string

Posted 02 June 2010 - 02:38 AM

you should try the ado recordset just google it
Was This Post Helpful? 0
  • +
  • -

#6 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: i need help comparing text from a text file, to string

Posted 03 June 2010 - 11:17 AM

Well I have my reasons for liking the flat file databases... I have used the ado record set and it just seemed clumsy, added controls to do one function. And I had to fill the database with one record, and not having the correct program to open an access file it made it hard.

I am pretty much scrapping the current project in favor to a new one I am hoping to get started this week, it was meant to be a small project and turns out that what I wanted to do was a jungle of code not worth the trouble, to hardly try to figure out. the idea was that the individual would want to build the data him/herself kind of makes the program more flexible. well the files I was trying to edit were for nothing more than navigation. that's it, so that you could navigate to the directory. and I only wanted it to print the info once with in the file so that when you navigated it would only show one year 2000 and not ten or fifty 2000's... so I am changing my direction to a new format. and we will see if this works.

Thanks,

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: i need help comparing text from a text file, to string

Posted 04 June 2010 - 12:56 AM

i am not ask you to convert your project to access just read this link Completely

About Ado and text files
Was This Post Helpful? 2
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: i need help comparing text from a text file, to string

Posted 04 June 2010 - 01:10 AM

oh nice reading :)
Was This Post Helpful? 0
  • +
  • -

#9 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: i need help comparing text from a text file, to string

Posted 04 June 2010 - 10:48 PM

View PostNoBrain, on 03 June 2010 - 11:10 PM, said:

oh nice reading :)


Well I needed to re work the whole structure anyway, I found that the program was attempting to open to many files and they were getting out of control, now they are in, and that I was in way over my head... so I worked it out to just print out from current year and print pack 100 years... I figure that it should be enough, since the user can create up to 5 years back with the way the form is setup, I also go it to add the years from the year selected to now. as far as the rest...

Its a better program now... I am not complaining, I kept most of the complex code that I had spent hours working on... such as my log in using encrypted files... works excellent, so I didn't change it. (I submitted it as a snippet, but think it got rejected... oh well)

I Hope every thing goes well for you all

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

#10 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: i need help comparing text from a text file, to string

Posted 04 June 2010 - 11:06 PM

View Postthava, on 03 June 2010 - 10:56 PM, said:

i am not ask you to convert your project to access just read this link Completely

About Ado and text files


I understand, However it is not what I need at this time, since it cant write to the files, which was the trouble I was having. I have gotten it to work, by just printing back 100 years, which should work until I can figure it out. thanks though, it was a good read.

Jesse Fender
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1