Sign in to follow this  
Followers 0
mcfr1es

Working With Text Files Easy Answer...

8 posts in this topic

#1 ·  Posted (edited)

For some reason the solution is just not comming to me...

I have a text files that has 50 items added to it countless times (1000 times actually). My question is, before I write those 50 items each time, how would i check to make sure that there is not an item on the list that is the same as the one that is just being entered.

this is what i Have:

$sURL = "http://www.neopets.com/neoboards/boardlist.phtml?board=1"
  $UserList = _GetUsers($sURL)
  
  $filename = "users.txt"
  FileOpen ($filename, 1)
;Check if file opened for writing OK
  If $filename = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
  EndIf
  
  For $wx = 1 to 50
    $ifexists = FileReadLine ($filename, $wx)
    If $ifexists <> $UserList[$wx]Then
      FileWriteLine($filename, $UserList[$wx])
    Else 
      MsgBox ( 3, "doubles", $UserList[$wx])
    EndIf
  Next
  FileClose ($filename)

The problem is that I cant use read line because the number of lines changes, unless instead of a line value i somehow use get size?

Edited by mcfr1es

Roger! You son of a big pile o' Monkey Nuts.

Share this post


Link to post
Share on other sites



For some reason the solution is just not comming to me...

I have a text files that has 50 items added to it countless times (1000 times actually). My question is, before I write those 50 items each time, how would i check to make sure that there is not an item on the list that is the same as the one that is just being entered.

this is what i Have:

The problem is that I cant use read line because the number of lines changes, unless instead of a line value i somehow use get size?

<{POST_SNAPBACK}>

I am a bit lost as to what you want to accomplish. The code looks somewhat strange trying to Read and Write from/to the same file... is this working ?

Looks to me you need to get your records and matching done in an arra7y and then when ready write the array to a file.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I am a bit lost as to what you want to accomplish. The code looks somewhat strange trying to Read and Write from/to the same file...  is this working ?

Looks to me you need to get your records and matching done in an arra7y and then when ready write the array to a file.

<{POST_SNAPBACK}>

Ok, lets make it simple, I want to write an array to a file but before i do so, i want to check to make sure the values im entering are not already in the file, and if they are, i do not want them written. How do i go about doing this?

Roger! You son of a big pile o' Monkey Nuts.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok, lets make it simple, I want to write an array to a file but before i do so, i want to check to make sure the values im entering are not already in the file, and if they are, i do not want them written. How do i go about doing this?

<{POST_SNAPBACK}>

I would read the records from the file into an Array.

Then check the value you want to write against the array first and when not found write it.

The thing i don't understand is that you talk about 50 records and about 1000 times.

Do you only want to compare against the first 50 records or all records ??

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I would read the records from the file into an Array.

Then check the value you want to write against the array first and when not found write it.

The thing i don't understand is that you talk about 50 records and about 1000 times.

Do you only want to compare against the first 50 records or all records ??

<{POST_SNAPBACK}>

sounds to me like he's trying to get usernames off of something like a forum with 50 users and 20 posts each, and he just wants a list of usernames without dupes...

"I'm not even supposed to be here today!" -Dante (Hicks)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

sounds to me like he's trying to get usernames off of something like a forum with 50 users and 20 posts each, and he just wants a list of usernames without dupes...

<{POST_SNAPBACK}>

exactly what emmanuel said and i want no dupes

(50 x 1000 actually...)

Edited by mcfr1es

Roger! You son of a big pile o' Monkey Nuts.

Share this post


Link to post
Share on other sites

I would read the records from the file into an Array.

Then check the value you want to write against the array first and when not found write it.

The thing i don't understand is that you talk about 50 records and about 1000 times.

Do you only want to compare against the first 50 records or all records ??

<{POST_SNAPBACK}>

Every time that 50 new records are added, i want it to check the text file to see if the values that im entering are already there and if not i wish them to be added

Roger! You son of a big pile o' Monkey Nuts.

Share this post


Link to post
Share on other sites

Every time that 50 new records are added, i want it to check the text file to see if the values that im entering are already there and if not i wish them to be added

<{POST_SNAPBACK}>

Read the list of users into an array that you can use durring program execution.

Then, for each new user, check it against the entire array, one element at a time (hint: you'll want a For loop for this task.)

If it does exist, you can continue onto the next user without adding the user, since that is already added to the array. If not, expand the array with ReDim, and continue onto the next name.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0