+ Reply to Thread
Results 1 to 17 of 17

Database in .txt file

  1. #1
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Database in .txt file

    I was thinking to make my own Soccer Database for now I´m only interested in storing FT result So that I can later look up teams for past performance later, So far this is what I got:

    The DataBase is stored in sheets Soccer,

    Please Login or Register  to view this content.
    This code works just as I wanted, However im a bit worried about adding duplicates to the database, so that is the reason why I came here, Was thinking that nothing should be added to the database if the same Date is already in it from before, How would I do That ?

    Any help is much appreciated as alway

    Ive attached the txt file and sample if anyone is interested.

    Frederik
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,660

    Re: Database in .txt file

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 12-31-2017 at 08:41 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    Hi thanks for your reply I had come up with quite similar solution myself late last night myself.

    Please Login or Register  to view this content.
    But my code did not exit the sub probably even though the if condition for the date was met . Thanks for your input I think this will be quite a big task, and I hope it will be easy to retrieve all of this data later .
    Last edited by colddeck84; 12-31-2017 at 03:26 AM.

  4. #4
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    Anyway looks like your edit works perfectly, couple of questions if you don't mind?

    Would it be possible to instead of search if date is in the .txt file , rather search each match in the sheet("soccer") and check if it is in the .txt file. and if not add matches that are not already stored. As I'm not sure how I should update this, Current setup would need to be updated after all matches for the the day is over , so basically on day behind.

    Also how fast will this be when the rows of the txt file exceeds 10 000 rows ?

    frederik

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,660

    Re: Database in .txt file

    I may be more efficient to have he macro mark the matches as logged in column N (or any empty column) on the sheet each day. Then the next day log only unmarked entries.

    The code below reads all the data en mas to an array then loops through the array. This is much faster than looping through each entry on the sheet. It's very expensive to access the sheet. Testing the values row by row accesses the sheet for each row. By using an array, the sheet is accessed only twice; once to read all the data and once to write the data.

    The first time you run this code, all the FT entries will be written to the text file because they are not marked as Logged in column N.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 12-31-2017 at 08:51 AM.

  6. #6
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    Hi thanks for your time looking into this.

    I may be more efficient to have he macro mark the matches as logged in column N (or any empty column) on the sheet each day. Then the next day log only unmarked entries.
    - its definitely easier to store it in a worksheet and I like how you solved this,
    but in all honestly I would really like to not have this Data stored in the worksheet.
    kinda beats the purpose of the .txt file

    The code below reads all the data en mas to an array then loops through the array.
    This is much faster than looping through each entry on the sheet
    - Yes you are right, I just made that quick code late last night much better approach adding to an array ,
    but with my skills I would need much long time to write the code that way

    -I was actually thinking regarding having it stored in worksheet, Maybe it could first load the .txt file
    into an array and then check if its logged ?

    edit: I can sea that your idea makes this process much simpler
    Last edited by colddeck84; 12-31-2017 at 10:35 AM.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Database in .txt file

    Why not just use a database? this is what constraints are for and it feels like you're reinventing the wheel

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,660

    Re: Database in .txt file

    Quote Originally Posted by colddeck84 View Post

    -I was actually thinking regarding having it stored in worksheet, Maybe it could first load the .txt file
    into an array and then check if its logged ?
    The text file data is not in a format that makes it easily loaded back into excel.

    Instead of checking if data is already written to the text file, it would be easier and more efficient to process all the data, both old and new, and completely overwrite the text file instead of just appending the new data to it..

  9. #9
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    Quote Originally Posted by Kyle123 View Post
    Why not just use a database? this is what constraints are for and it feels like you're reinventing the wheel
    Sounds like a good plan, obviously Im no expert with this stuff where would I get an database ?
    ,

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2511 (Windows 11 Home 24H2 64-bit)
    Posts
    92,898

    Re: Database in .txt file

    Do you have Microsoft Access in your Office suite?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Volunteer organiser & photographer with the Sutton Hoo Ship's Company: https://saxonship.org/
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  11. #11
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    Yes I have it
    Last edited by AliGW; 12-31-2017 at 11:24 AM. Reason: Unnecessary quotation removed.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2511 (Windows 11 Home 24H2 64-bit)
    Posts
    92,898

    Re: Database in .txt file

    Great. Access is database software. It comes with lots of templates, so you should be able to find one that suits your needs. It will take a bit of learning, though.

  13. #13
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    This will be a lot of information to address today. I just figured out how to write all of this data as a proper .CSV file makes the data easier to handle , something like this:

    Please Login or Register  to view this content.

  14. #14
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,660

    Re: Database in .txt file

    If the whole point of the text file is to backup your data, why not just save a copy of the workbook. Or is there a reason to save it as a text file.

    Also, you could autofilter column E for "FT" and use SaveAs xlCSV

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    thanks alot for all the answers and even on new years eve I think im very close to a solution that might work for me now. Here is my latest edit which will organize all the data niceley into a .csv file
    AlphaFrog : sorry but I wouldn't know how to make an array of this latest edit.

    Please Login or Register  to view this content.
    Also, you could autofilter column E for "FT" and use SaveAs xlCSV
    This might be a good option, I didnt know about that.
    If the whole point of the text file is to backup your data, why not just save a copy of the workbook. Or is there a reason to save it as a text file.
    - At a later point I think im gonna take my current project out of excel completely. For now im currently in need of a database that the rest of my project it dependent upon. and I try as best as I can to not have to many "dummy" sheets

    Here is how its working in my end:
    Step 1. Load Data. All results up to NOW are loaded for current date.
    Step 2. would be to load all of this into .csv file
    step 3 would be to avoid duplicates
    step 4 clear data in excel sheet or keep as it is.

    I was thinking to load all of the csv. data into an array but not if the date is same as in COL D. then it should add data from excel into same array, then overwrite everything in the .csv file.

    I think that could be doable ?

  16. #16
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    removed post.
    Last edited by colddeck84; 12-31-2017 at 06:01 PM.

  17. #17
    Forum Contributor colddeck84's Avatar
    Join Date
    06-18-2016
    Location
    bergen, norway
    MS-Off Ver
    2016
    Posts
    254

    Re: Database in .txt file

    I finally have something to work with:

    Please Login or Register  to view this content.
    * This code will add everything from csv file into an array as long as the date is not presented in cell(12,"D")
    forget about the database2.csv (its just for testing)

    * Then I can add to the arr from the sheet without no worry about duplicated dates

    I kinda wished I had this stored as an multidimensional array instead of a 1d. Would be easier to work with the data that way but making this little snippet of a code have taken me several hours.

    Thanks alot guys for all your inputs.
    Last edited by colddeck84; 12-31-2017 at 06:18 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Uploading a file to your database
    By Brooksdt in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-01-2017, 07:38 PM
  2. Database file
    By gombi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-15-2012, 02:48 PM
  3. Opening a database file
    By Eucarionte in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2008, 06:19 PM
  4. creating a yearly database file using info in daily file
    By bilbobagginz in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-12-2008, 09:47 AM
  5. How to use Database file in Excel
    By tqm1 in forum Excel General
    Replies: 3
    Last Post: 04-30-2007, 04:34 AM
  6. Replies: 0
    Last Post: 05-20-2005, 02:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1