Search code examples
visual-studioautosave

Storing user input (Visual Basic)


I'm creating an application that will take a number of user inputs, store the data for a while, and eventually (at the end of the day) export it to an excel file.

An example might be that a user would input what they did throughout the day. Breakfast/At Home/for 10 minutes. Then later on they would input Coding/At Work/8 hours. Then later on Commuting/Subway/15 minutes. Etc.

I can handle the user interface, and the exporting to excel.

I'm just wondering what might be the best way to store that data and display it back to the user while the program is running. I'm used to working with macros in Excel itself, where I could simply store each row of data in another row on the excel spreadsheet itself.

I would still like a spreadsheet-like display, so that the user can go in to each data point and correct any mistakes. But I am making this as a standalone application using visual basic. Fortunately, I think the ListView or DataGridView tools will let me do this.

At the moment the method I'm thinking of using is simply to store all the user inputs in an array. But I would have to ReDim the array and increase its size each time the user created a new entry.

I can already see a problem with this, however, and that is that an array would have to be constantly stored in active memory. If the user's computer were to crash then all the data would be lost for good.

I'm really a rookie here, so I could use some guidance on how to store a bunch of user inputs like this.


Solution

  • You can use a database file. A local Sql Server Compact Editon database (a single file) that will store your data. You can use Entity Framework to interact with this database.

    If you want to use Code First (generate your database from your code) use this: https://www.codeproject.com/Articles/680116/Code-First-with-SQL-CE

    If you want to use Database First (generate your entities from your database) use this: http://erikej.blogspot.com/2013/11/entity-framework-6-sql-server-compact-4_25.html

    You can also use SQLite or other kind database file, but i like SQL Server CE