Page 1 of 2 12 LastLast
Results 1 to 40 of 44

Thread: Advice On Storing Member Data in Text Files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Advice On Storing Member Data in Text Files

    Hello I am making a Client/Server Program where Members Register An Account but instead of using a database I am opting to use text files instead. I may utilize a database at a later time but for now I would like to learn how to setup my program to use text files for this project.

    So my question is, what is the best way to store the members data in the text file meaning the look of it. I know many things use comma delimited text but would it matter if I just setup my own way of doing it? It probably does not matter I am sure I can do any way I can think of but just figured I would get some advice on it.

    Example:

    First Name: John, Last Name: Robertson, User Name: NewGuy123, Email: JRobertson72@example.com, Password: 55571480, Phone: 516-555-5555, Country: USA, Address: 711 Rock Street, City: Bedford, State: FL, Zip Code: 11733, Registered Date/Time: 9/15/2020 - 5:02 PM

    I was going to just store these as one line across but also considered doing it vertically, something like this:

    [FIRST NAME] John
    [LAST NAME] Robertson
    [USER NAME] NewGuy123
    [EMAIL] JRobertson@example.com
    [PHONE] 516-555-5555
    [COUNTRY] USA
    [ADDRESS] 711 Rock Street
    [CITY] Bedford
    [STATE] FL
    [ZIP CODE] 11733
    [DATE TIME JOINED] 9/15/2020 - 5:02 PM

    brackets don't matter I just need any way of separating it to look neater, it could be [] or , or : or |
    it does not matter much but I was thinking of doing it vertically like above so if I ever wanted to just read it fast I could just open the file and read it easier than across..

    What do you guys think, how should I do this? I realize this is an easy thing for most people but I get indecisive so quickly about these things.

    I think one thing is that it needs to state the field first, example First Name, and then seperate their First Name from that like First Name: Paul and then have another separator to show the entry has stopped like First Name: Paul, and then the next entry.. etc.. First Name: Paul, Last Name: Jenkins,
    Last edited by DreamWarrior77; Sep 15th, 2020 at 04:18 PM.

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Advice On Storing Member Data in Text Files

    You could create a class containing a structure called member with all the information about the member and containing a list(of member) then export/import the object created (members) with that class as an xml file using an XmlSerializer.

    https://docs.microsoft.com/fr-fr/dot...ew=netcore-3.1
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Advice On Storing Member Data in Text Files

    Quote Originally Posted by DreamWarrior77 View Post

    brackets don't matter I just need any way of separating it to look neater
    How the file looks to the human eye should not be a consideration at all. It should be in a format that is easiest to work with (parse).

    If you want a pretty looking file, write yourself a side-utility that takes your main data file and exports it into a format that you like the look of.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Thanks Delaney but that seems like something I would not be able to figure out just yet. I have something else in mind but do appreciate your input very much! Thank You
    ok Optionbase1, I Thanks for your response, yes that makes sense to me, ok so if I want to parse this data very easily what would be the easiest way?
    What vb .net function/command do I use to parse the data?

    say if it is like

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280

    I need to parse all these entries and then load them into the appropriate datagridview cells.
    I just need help to figure out how to do this.

    Thanks

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Advice On Storing Member Data in Text Files

    The easiest way is with a database, believe it or not. You may think that going down the road of a "simple" text file is easier, but it isn't. There are tons of examples of how to use a database file in VB.NET, so there's no excuse to not use one.

    Going down the road of a text file, think about this: Once you've chosen a delimiter, what if a user uses that delimiter in one of the fields they fill out? Your code could blow up pretty quickly in that case. That's just one of many significant concerns with what you are trying to do.

    I would imagine that because trying to use a text file for this is going to be seen as a very non-optimal solution, the odds that you will get a bunch of useful feedback is small, and the odds of being given any sort of code samples is essentially nil.

    Good luck.

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Advice On Storing Member Data in Text Files

    Think we had this discussion before. lol

    anyway if your heart is set on using a Text file then just Google "visual basic import a csv file"

    CVS stands for a Coma Separated Variable, it's a Text file. There are lots of videos and examples.

    Here's simple 2 minute video (volume is low) https://www.google.com/search?q=visu...DaswX8sZnYDQ36

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Advice On Storing Member Data in Text Files

    Quote Originally Posted by DreamWarrior77 View Post
    I may utilize a database at a later time but for now I would like to learn how to setup my program to use text files for this project.
    So you might do the right thing later but right now you want us to help you do the wrong thing? Got it.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Advice On Storing Member Data in Text Files

    One thing to keep in mind is that there are some legal and security issues that become relevant if you intend to use this solution for anything other than practice. If this is just for practice, and the data isn't real, then you can do what you want. Also, depending on where you are located, the laws around data storage may be more strict or more lenient, but the information you are indicating you are storing is sufficient that you'd have to pay close attention to data security in many countries.

    I would second the views of others that you'd be better off using a database right from the start, as this approach is going to become painful for more than just a few people, but if this is just for practice, then go for it. If that is the case, then you might consider using a datatable, as you can then use the methods of the datatable to serialize/deserialize to and from an XML file, which would give you structure with minimal effort. That would also be utterly insecure, but that appears to not be a concern for you, yet, at this stage.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    So you might do the right thing later but right now you want us to help you do the wrong thing? Got it.
    That is your opinion, Linux/BSD Systems use Text Files For many things so it's really a moot point.
    There really is no wrong way of doing it, and for now I like the idea of using text files.

    so my question is how can I parse data if this was my format:

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280

    How can I use the String Split Function To separate |First Name:Tom and Just Return Tom? and keep doing the same for the rest of the entries?

  10. #10
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Advice On Storing Member Data in Text Files

    Why did you pick that format knowing that you would need hand-holding in order to be able to use that format?

    Why should anyone here spend their own time helping you do something that they are recommending you not even do in the first place?

    Use a database. It is my opinion (and everyone else's) because it is the right option.

    Good luck.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Shaggy Hiker -
    this approach is going to become painful for more than just a few people
    assumptions.. what people and why, no has an idea of what exactly I am even trying to do with the project.
    I am not storing Credit Card Information or any other electronic payment info, sure they are always security concerns but this a learning process for me and this is the current route I am taking with this project.

    I may change how things work at a later time. If anything I would go with something maybe like Maria DB or mySQL, I just don't know anything about them or how to set them up and organize my tables so it could make sense.

    It would probably take quite a while for me to get my head around using one of those. Out of Maria Db and mySQL what is easier to setup with tables fast?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    ok I am on a help forum where no one wants to help. I don't understand what the hot debate about this is, this is a programming forum in which I can program any way I want to and not be required by random members to do a personal programming project their way. This is not your programming project it's mine, so please relax. I came here for help not to catch a beat down for God sake.

    splitting the string should not be rocket science I just need help understand how to approach it.. if anyone can help me on this helpful forum.

  13. #13
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Advice On Storing Member Data in Text Files

    No one wants to help? Doesn't multiple people telling you that you are making a bad decision in your approach and that you should be doing it differently constitute help? I guess not. Do you think we are all doing that to troll you?

    You are free to write any code in any way you want. Just don't expect a lot of people to help you do it the hard way when you've been told many times by many people that doing it that way is a mistake.

    Of course splitting the string up isn't rocket science. But we all know that if someone helps you with that one piece, you are then going to run in to the next issue that you will need help with. And the next, and the next. A database solves all of the problems you already can think of, and all of the ones you haven't encountered yet because you haven't gotten that far. That's the bottom line.

    I wish you the best with this project.

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Advice On Storing Member Data in Text Files

    Quote Originally Posted by DreamWarrior77 View Post
    Shaggy Hiker -

    assumptions.. what people and why, no has an idea of what exactly I am even trying to do with the project.
    I am not storing Credit Card Information or any other electronic payment info, sure they are always security concerns but this a learning process for me and this is the current route I am taking with this project.
    Yeah, I get that up to a point. We just got a pretty lengthy lecture on personally identifying information law in the US, and it's a bit more exacting than you might expect (especially considering how many large companies get in trouble with it), so my point was that, if you intend to use this for a real project, you will want to figure out your legal liabilities regarding data storage.

    However, the point about it becoming painful has to do with search more than anything else. When somebody logs in, you'll want to find them among the records you have based on user name and then password. Searching is what databases are particularly good at, while text files are not so good at allowing searches. As long as the number of people on record is small, search is not important, since any method will work well enough. Once the number of people increases, the cost of search starts to become increasingly important.

    That's also why I suggested the datatable approach. What you have already laid out is a structured file, which is all that XML is, though the structure is different. A datatable has simple methods for reading and writing XML, so you can get a structured text file in and out with effectively no effort if you switch to the XML structure.

    Of course, XML is also bulkier than what you have, so the file will be larger, but the reading and writing couldn't be simpler. For the format you described, your best performance is probably going to be to explore ReadAllLines to get every record into an array, then parse the array using Split to divide each line up into elements, then put the elements into objects designed to hold them, of which the most obvious is a datatable. So, back to that.

    Another alternative that would be closer to what you have described than XML, but which isn't quite as simple to use with a datatable as XML, is JSON.
    My usual boring signature: Nothing

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    But we all know that if someone helps you with that one piece, you are then going to run in to the next issue that you will need help with.
    Right but this is a help forum is it not!? Am I in the wrong place or something? We are not all uber programmers just yet which is why we are on the forum to begin with.
    Making excuses not to help people who need it is only causing me and other people stress, as well as putting them off from programming in general.

    When I started with VB in high school it was for fun, a hobby that I enjoyed. Now all this you have got to do it this way or die stuff. Too stressful..

    it is my project and I would need help anyway I look at it, doing a database would only be more difficult I feel. Even though more proper, more complicated.

    If you wanted to go in a certain direction with your project I am sure I would not shoot you down about it, but yes I do appreciate what everyone is saying about using a database.
    Again I have much to learn about using databases still so it is not the most immediate option at this moment for me.

  16. #16
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,041

    Re: Advice On Storing Member Data in Text Files

    Quote Originally Posted by DreamWarrior77 View Post
    Thanks Delaney but that seems like something I would not be able to figure out just yet. I have something else in mind but do appreciate your input very much! Thank You
    ok Optionbase1, I Thanks for your response, yes that makes sense to me, ok so if I want to parse this data very easily what would be the easiest way?
    What vb .net function/command do I use to parse the data?

    say if it is like

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280

    I need to parse all these entries and then load them into the appropriate datagridview cells.
    I just need help to figure out how to do this.

    Thanks
    first you should rethink your Format, do you really want to right ... Firstname:Tom
    on each line ? no I think not

    consider a Text file or a CSV File with Headers...
    Firstname Lastname User etc...

    then you could split like this
    Code:
     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim s1 As String = "|Tom|Johnson|TJohnson17|example90@example.net|516-555-5555|USA|17 Watercrest Lane|Bizmark|NY|11280"
            ' Split the string on the character.
            Dim parts As String() = s1.Split(New String() {"|"c}, StringSplitOptions.None)
            ' Loop through result strings with For Each.
            Dim part As String
            For Each part In parts
                Debug.Print(part)
            Next
        End Sub
    but then again what row in this Text file or CSV file do I want to split ?


    I would use and advise you to use a Database, just like the others
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  17. #17
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: Advice On Storing Member Data in Text Files

    If not a database then definitely an XML file.

    Code:
            Dim foo As XElement
            foo = <users>
                      <user>
                          <fnm>John</fnm>
                          <mnm></mnm>
                          <lnm>Robertson</lnm>
                          <unm>NewGuy123</unm>
                          <email>JRobertson@example.com</email>
                          <phone>516 - 555 - 5555</phone>
                          <country>USA</country>
                          <address><![CDATA[711 Rock Street
    Apt. #1]]>
                              <city>Bedford</city>
                              <state>FL</state>
                              <zip>11733</zip>
                          </address>
                          <join>9/15/2020 5:02 PM</join>
                      </user>
                      <user>
                          <fnm>Jill</fnm>
                          <mnm></mnm>
                          <lnm>Smith</lnm>
                          <unm>NewWoman123</unm>
                          <email>jsmith@example.com</email>
                          <phone>516 - 555 - 1234</phone>
                          <country>USA</country>
                          <address><![CDATA[1 Foo Street]]>
                              <city>Valpariso</city>
                              <state>FL</state>
                              <zip>12345</zip>
                          </address>
                          <join>9/16/2020 5:02 AM</join>
                      </user>
                  </users>
    
            'find a user
            Dim user As IEnumerable(Of XElement)
            user = From uel As XElement In foo...<user>
                   Where uel.<unm>.Value = "NewWoman123" Select uel
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Thanks dbasnett, I am not familiar with XML yet though.. but I do appreciate your response Thanks

    I may try to go the mySQL route, going to create a new thread for it now but still want to know how to do this just to be able to, should I require to do so.

    ok the problem with your code example ChrisE, is that in the function code or sub this line is not hard coded:

    Code:
    Dim s1 As String = "|Tom|Johnson|TJohnson17|example90@example.net|516-555-5555|USA|17 Watercrest Lane|Bizmark|NY|11280"
    what I mean is that the member text files it downloads are always different from each other, it's never hard coded like that, always different user data
    which is why I had the First Name and other separators there so I can programmatically just take whatever is after the place holders as the users data somehow.
    I just need help to do this in a better way.

    For example if I could just read through the line

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280

    and search for |First Name: and only take what is to the right of it until I reached the next one which would be |Last Name: and then again, only take the data to the right of it until I reached the next one and so on until the last one..

    this is what I was going for, I am sorry sometimes it takes me a long time to realize how I want to do things.
    Last edited by DreamWarrior77; Sep 16th, 2020 at 01:08 PM.

  19. #19
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Advice On Storing Member Data in Text Files

    what I mean is that the member text files it downloads are always different from each other, it's never hard coded like that, always different user data
    Are you saying that all line in the text file are not in the same format?

    Tom|Johnson|someemail|555-555-5555|USA
    Bob|Johnson|555-555-5555|USA|someemail

    What a nightmare. lol

    If that's true and you have no control over the text file format then you will have to write a custom import. If at all possible the text file needs to be in a consistent format otherwise this will be extremely hard to work with and will require large amounts of extra programming.

    VB has many built in tools for dealing with importing text files but the file do need to follow certain rules.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    No Wes, it is always the same format, not sure where you got that idea. It is always the same format but the data itself is different is what was meant.
    Meaning that in his example code to parse the data it would never always be:

    |Tom|Johnson|TJohnson17|example90@example.net|516-555-5555|USA|17 Watercrest Lane|Bizmark|NY|11280

    but different users with different data, same exact format for each member of course.

    I just need to search for each part and extract the user data for example |First Name:John
    where John is the data I need to extract and the same method for the whole line for each part required.

    Then I need to load this member data into cells in a datagridview, and possibly a member profile form that contains some extra data that is not being listed inside the datagridview control.

  21. #21
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Advice On Storing Member Data in Text Files

    Wait, so all your users won't be named Tom Johnson?

    Chris provided some very plain example code with example data to demonstrate how it might work.

  22. #22
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: Advice On Storing Member Data in Text Files

    Quote Originally Posted by DreamWarrior77 View Post
    what I mean is that the member text files it downloads are always different from each other, it's never hard coded like that, always different user data
    which is why I had the First Name and other separators there so I can programmatically just take whatever is after the place holders as the users data somehow.
    I just need help to do this in a better way.
    Yikes...
    What is the source of this file then? Is it something in your control? The assumption was thaat your app was what created and maintained it... now... I'm not so sure.

    I'm going to toss something out there... hopefully it isn't too far out of your toolbox: a Dictionary(Of String, String)... it's a way of storing key/value pairs... in this case pairs of strings...
    So once you parse the line, you loop through your array, and parse each element... then add to the dictionary dict.add(elm[0], elem[1]) ... for each line, you'll need to create a new Dictionary... don't try to add to the same one ... now if you want to keep that... you can put it into an array... or a List(Of Dictionary(Of String, String))
    I've got to take off now, or I'd hack out an example... but that might get you closer to whetre you're going. Maybe someone else can tap one outfor you, or try google.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  23. #23
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Advice On Storing Member Data in Text Files

    Just for grins I wrote some code for importing a file in your desired format. This will actually import correctly even if the text file columns are not in the same order.

    Code:
    Public Class Form1
        Private gridDataTable As New DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    
            With gridDataTable.Columns
                .Add("First", GetType(System.String))
                .Add("Last", GetType(System.String))
                .Add("User", GetType(System.String))
            End With
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim theReader As New IO.StreamReader("c:\a2017Templates\test.txt")
            Dim sline As String
    
            Do
                sline = theReader.ReadLine
                If sline = Nothing Then
                    Exit Do
                End If
                Dim theColumns = sline.Split(Chr(124))
                Dim cntr As Integer = 1
                Dim row = gridDataTable.NewRow
                Do While cntr < theColumns.Length
    
                    Dim selectString = theColumns(cntr).Substring(0, theColumns(cntr).IndexOf(":"))
                    Select Case selectString
                        Case "First Name"
                            row("First") = theColumns(cntr).Substring(theColumns(cntr).IndexOf(":") + 1)
                        Case "Last Name"
                            row("Last") = theColumns(cntr).Substring(theColumns(cntr).IndexOf(":") + 1)
                        Case "User Name"
                            row("User") = theColumns(cntr).Substring(theColumns(cntr).IndexOf(":") + 1)
                    End Select
                    'MessageBox.Show(selectString)
                    cntr += 1
                Loop
                gridDataTable.Rows.Add(row)
    
                Loop
    
                Me.DataGridView1.DataSource = gridDataTable
        End Sub
    End Class
    File contents,

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17
    |First Name:Bob|User Name:TJohnson18|Last Name:Johnson
    |First Name:Steve|Last Name:Jones|User Name:TJones17

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Thanks techgnome, I will need to read into how this works more though, I will try doing some google searching about it. I am a visual learner 100% though, so seeing examples definitely helps my mind to better realize and understand how it can be used. If I can see how it can be used in the context that I needed it, this would be very helpful.

    Basically it is a project that is not typical by any means, but it is how I wanted to start to do this.

    Basically I will have a wordpress plugin for a few simple things, member registrations, affiliate ID's and optin affiliate leads (first name and email, something like that..), so they will signup via a wordpress registration form, creating an account, getting sent email about it while the plugin creates a text file in a sub folder on the hosting server for each member. In a folder called Members.. my server program basically will just for now anyway download/import all these Member Text Files from the Hosting Server and Split the Data Required into a datagridview to Manage The Members Data. I will also need to Update their Data via The DataGridView and Save Their Updated Text File Back To The Server.

    So while this may sound simple for some it is fairly difficult for me at this time.
    I have difficulty concentrating and remembering things so it has been rough.

  25. #25
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Advice On Storing Member Data in Text Files

    How are you going to store/protect the user's password in these text files? It sounds like what you are trying to set up is some sort of commercial enterprise (small scale at the very least) here.

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Optionbase1, wordpress will be taking care of user passwords so I should be fairly secure with that.. unless I decide to also include it for admin purposes in their member text file but in that case, I will probably use some form of encryption for that.

    Cool Thanks wesdbt, ok I am a slow learner unfortunately so I will need to slow this down a lot to get a grip on what I am doing and understand it better.
    ok I have a form with my datagridview on it with named cells that go with the names in the formatted text files. Example, First Name in text file and First Name in datagridview cell.
    They are matched to get loaded like this.

    Ok now I just created a text file that has my example formatted text in it which is:

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280|

    I added one more | on the end just to make it neat, and also because I will be adding more to this members data entry soon.

    ok but anyway, now, I have my form with the datagridview and a menu with:

    Code:
    Private Sub AddParsedUserDataToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddParsedUserDataToolStripMenuItem.Click
            OpenFileDialog1.FileName = ""
            OpenFileDialog1.Title = "Open Member Data File"
            OpenFileDialog1.InitialDirectory = "c:\"
            OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            OpenFileDialog1.FilterIndex = 1
            OpenFileDialog1.RestoreDirectory = True
    
            If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    
                Dim myfile As String = OpenFileDialog1.FileName
                Dim allLines = File.ReadLines(myfile)
    
            End If
        End Sub
    So I am opening the OpenFileDialog and Selecting my file to Process but now stuck as to what to do next.
    I am sorry to be a burden but I need to slow it down a bit to really understand what I need to do to make it work.
    Where would I go from here with this?

    If I select the file it and load it, it will read all lines of the file but I wanted to test that it is being read with a msgbox but it is giving me an error about it..

    "System.ArgumentException: 'Argument 'Prompt' cannot be converted to type 'String'.'"

    that is after I placed this code:

    MsgBox(allLines)

    how can I test to see if it is reading the file?
    I like to test with msgboxes, what have I done wrong here?
    Last edited by DreamWarrior77; Sep 16th, 2020 at 03:50 PM.

  27. #27
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Advice On Storing Member Data in Text Files

    Typically, you shouldn't store a password. What you store is the hash of the salted password. You can't get the password back from that, so it is secure, but if the user enters some password, which is then salted and hashed, the resulting hash should match the hash you have stored. You don't know the password and aren't storing it, which means it's secure (with a caveat) in case anybody steals the data.

    A hash is just a one-way encryption. You can't decrypt it, but the same phrase will always result in the same unique hash. The salting is just about adding extra characters to whatever password the user enters to increase the size of the password, as the larger the password, the harder it is to crack the hash.
    My usual boring signature: Nothing

  28. #28

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Well the thing is everyone's situation is somewhat different. I am not storing too much sensitive data like credit card info or bitcoin info and stuff like that.
    Just Name/User Name/Address/Email/Phone/IP/Statistics..

    I may store passwords only for admin purposes, for example a user who needs help with their account, but I am not sure I will need to really do this to be honest.
    I won't know until I develop the project more, most people are pretty tech savvy these days but you never know if any older users may need help with stuff.
    For that situation though, well written tutorials on how to use the program should suffice and be enough to help them.
    I just don't know if I will even need to store it anyway but if I did I would use some encryption even if fairly simple, at least someone can't read it if any data was stolen,
    but it seems doubtful. I should make precautions regardless though and I will as I progress with it.

  29. #29
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Advice On Storing Member Data in Text Files

    Hello,

    In France ( and more generally in Europe) this
    Name/User Name/Address/Email/Phone/IP
    are sensible data especially if they are together and should not be stored on any cloud or computer with internet access without a minimum of security (password to open the file, encrypting, etc.), I am sure it is the same or similar in a lot of countries.

    have a look just for information : https://translate.google.fr/translat...re2%23Article5
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  30. #30

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Yeah now that we got GDPR we need to take that into account..
    I will add security measures as it develops but for now I just need basic functionality just to test program features and functions.
    Things will be added later to make it more secure.. encryption, password locked files only unlockable by the program or admin.

    Thanks Delaney

  31. #31
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Advice On Storing Member Data in Text Files

    You could store the data as JSON (see office website). What you would do is create POCO class (see wiki), deserialize the text file into a collection, and serialize it back into the text file.

    At a high level these are the steps:
    1. Add the Newtonsoft.Json reference to your project using NuGet (instructions here)
    2. Import the reference to your class file
    3. Create a class to represent your stored data
    4. Declare a collection (type would be the class representation) at a global level
    5. When you want to read the file you will want to do a few things:
      1. Check if the file exists using IO.File.Exists (documentation here)
      2. If not, create one where the text is just an empty JSON array: []
      3. Read all of the text using IO.File.ReadAllText (documentation here)
      4. Convert the String to a collection of the class representation you created earlier using JsonConvert.DeserializeObject (documentation here)
    6. When you want to write back to the file you will want to do a few things:
      1. Check if the file exists using IO.File.Exists; it may've been deleted since you've read it earlier
      2. If not, create one where the text is just an empty JSON array
      3. Get the serialized String of your collection using JsonConvert.SerializeObject (documentation here)
      4. Write the text to the text file using IO.File.WriteAllText (documentation here)


    Of course you should listen to the advise that many on here have given related to both security and performance.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  32. #32

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    ok now I did some searching for this msgbox error and it seems that I need to convert
    Code:
    Dim allLines = File.ReadLines(myfile)
    into a string so the msgbox can display it properly but I can't seem to figure this out.
    I tried
    Code:
    MsgBox(allLines.ToString())
    and it displayed "System.IO.ReadLinesIterator" in the message box..

    what gives?

  33. #33
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Advice On Storing Member Data in Text Files

    If you want to use my code then, add a form to your project, add a DataGridView (no need to add columns thats being done in code), add a button to the form. Then copy my code to the form1.

    You'll have to change the file name - Dim theReader As New IO.StreamReader("c:\a2017Templates\test.txt"). I'd suggest just hardwiring it while your developing and testing. No need to keep having to select the file everytime you test. You can easily add the Open File dialog later.

    My example does not use File.Readlines so I'm not sure why you are. If you want to use that then don't use my example.

    Once you've figured out how the code works then start expanding the import file so it include the other fields and add the necessary code. Don't try an do it all at once.

  34. #34

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Thanks wes4dbt, ok I tried what you said, I added a datagridview control and a command button/code, then added the form code.
    I replaced the file path with my own but it is giving me an Exception Unhandled Error: System.ArgumentOutOfRangeException: 'Length cannot be less than zero.
    Parameter name: length'

    on line 25 which is
    Code:
    Dim selectString = theColumns(cntr).Substring(0, theColumns(cntr).IndexOf(":"))

  35. #35
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Advice On Storing Member Data in Text Files

    Did you use the same data I used? Or a file with that EXACT same format?

    If so, then post your code and a sample of the import file.

    My guess is you added the "|" field separator to the end. You shouldn't do that, when someone gives you an import example, you need to run it with data formatted exactly the same.

    This is a very simple example, it's intent is to give you an idea of what your import will look like. There still maybe be some very important things that need to be added. Like data verification, when you use things like "substring" and "IndexOf" you're making certain assumptions, like there will always be data and no empty fields. So no records will be missing any First Name, Last Names, Phone Number, Addresses......... If not then you'll need to do data verification.
    Last edited by wes4dbt; Sep 16th, 2020 at 08:30 PM.

  36. #36

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    This was the code used

    Code:
    Public Class Form1
        Private gridDataTable As New DataTable
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With gridDataTable.Columns
                .Add("First", GetType(System.String))
                .Add("Last", GetType(System.String))
                .Add("User", GetType(System.String))
            End With
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim theReader As New IO.StreamReader("C:\Users\My Name\Desktop\Example Member Data File To Parse.txt")
            Dim sline As String
    
            Do
                sline = theReader.ReadLine
                If sline = Nothing Then
                    Exit Do
                End If
                Dim theColumns = sline.Split(Chr(124))
                Dim cntr As Integer = 1
                Dim row = gridDataTable.NewRow
                Do While cntr < theColumns.Length
    
                    Dim selectString = theColumns(cntr).Substring(0, theColumns(cntr).IndexOf(":"))
                    Select Case selectString
                        Case "First Name"
                            row("First") = theColumns(cntr).Substring(theColumns(cntr).IndexOf(":") + 1)
                        Case "Last Name"
                            row("Last") = theColumns(cntr).Substring(theColumns(cntr).IndexOf(":") + 1)
                        Case "User Name"
                            row("User") = theColumns(cntr).Substring(theColumns(cntr).IndexOf(":") + 1)
                    End Select
                    'MessageBox.Show(selectString)
                    cntr += 1
                Loop
                gridDataTable.Rows.Add(row)
    
            Loop
    
            Me.DataGridView1.DataSource = gridDataTable
        End Sub
    End Class
    and the text inside the text file is:

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280|

    we can get this example working to try to see what we can do for now but I basically in the end want to have a datagridview with pre named fields that I will just parse the member text files and load the data into the proper cells. Just going from left to right and parse out the needed data. I just don't know how to do this yet. I know in VB6 we used an Len Command or something..?

    I am assuming that meant Length?

    So I am hoping to find something like that that can read it across and then place into the Pre mapped out DGV Cells.

  37. #37
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Advice On Storing Member Data in Text Files

    -slowly backing away-
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  38. #38
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Advice On Storing Member Data in Text Files

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280|
    Does that look like my sample data. Why would you expect that to work. I've tried to make my instructions and examples as clear as possible but I don't seem to be getting any where. You can't get this simple example working and your worried about "pre named fields" so the data gets into the proper cells. Well that's exactly what this example does if you would just follow instructions. It's done when you create the DataTable. You don't have any idea what going on in the code but your sure it doesn't do what you want. If you want to create the dgv header names in the designer you can but it's not necessary and completely irrelevant to the example I provided.

    Maybe someone else can explain things better, good luck

  39. #39
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,041

    Re: Advice On Storing Member Data in Text Files

    Quote Originally Posted by DreamWarrior77 View Post
    Ok now I just created a text file that has my example formatted text in it which is:

    |First Name:Tom|Last Name:Johnson|User Name:TJohnson17|Email:example90@example.net|Phone:516-555-5555|Country:USA|Address:17 Watercrest Lane|City:Bizmark|State:NY|Zip Code:11280|

    1) I added one more | on the end just to make it neat, .....

    2) what have I done wrong here?
    follow the Instructions you got from Wes

    1) did Wes add a | at the end to make it neat ?
    2) well what did you do wrong then= see 1)
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  40. #40

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2018
    Posts
    395

    Re: Advice On Storing Member Data in Text Files

    Sorry about that yes I fixed it and removed the extra | and it now works, Thanks
    I will need to analyze and adjust it to work for my needs..
    My brain is too tired right now but I will post back when I am refreshed again. Thanks for all your help yesterday/today to everyone who posted!

Page 1 of 2 12 LastLast

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