Results 1 to 4 of 4

Thread: Saving data when Project closes VS10

  1. #1
    Member
    Join Date
    Aug 11
    Posts
    47

    Saving data when Project closes VS10

    I've got a quick question.. If I built a program with say an array of:
    Code:
    Dim X(6) As Integer
        X(0) = 0
        X(1) = 1
        X(2) = 2
        X(3) = 3
        X(4) = 4
        X(5) = 5
        X(6) = 6
    What would be the best way to save the data the array has been given so that next time when I open my project I can retrieve the data so the user can use it again. I mean my first thought would be to write it to .txt file and then open and re import it when the program started up again, maybe an xml file, or even a datase of some sort, but isn't there a diffrent way of doing it? I've heard of Project->Properties->Settings never really used them before but I wasn't sure if they allowed arrays to be saved, what i've seem it looks like just single strings of data. It's not like it's going to be millions of rows of data you know maybe 100 most *Not sure on the number yet*...

    Thanks,
    Brian

  2. #2
    .Net Member dday9's Avatar
    Join Date
    Mar 11
    Location
    South Louisiana
    Posts
    2,202

    Re: Saving data when Project closes VS10

    If you're going to have atleast more than 5-6 then I wouldn't suggest using my.settings. There is a stringcollection type setting, but since X is an integer I wouldn't suggest using that. If security isn't an issue, then a textfile would suffice. If security is a bit more of an issue then I would use a sql/access database. Either way is easy to use. If you want the data to save when the form is closing then put the code to update the array in your form_closing event. An example of using e.Cancel in the form_closing would be:
    Code:
    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            If MessageBox.Show("Do you want to close?", Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
                e.Cancel = True
            End If
        End Sub
    Also, might I suggest using a loop to set those arrays? Something like this:
    Code:
    Dim x(6) As Integer
            For i As Integer = 0 To x.Count
                x(i) = i
            Next
    It's a little easier on the fingers :P

  3. #3
    Member
    Join Date
    Aug 11
    Posts
    47

    Re: Saving data when Project closes VS10

    Thanks for the tips, I acutally should of put the example as a string because it will be declared a string not a integer. Sorry for that, when I was typing out the example I guess I just wasn't thinking about at the variable. So I will have to look into this stringcollection type setting also or just set it to a textfile. Currently it's just a project for me, but in the future I might allow other people to use it and I just didn't want them to be able to access the txt file and edit it in any form basically.

    Thanks again

  4. #4
    .Net Member dday9's Avatar
    Join Date
    Mar 11
    Location
    South Louisiana
    Posts
    2,202

    Re: Saving data when Project closes VS10

    Well like I said, even if you were to use the stringcollection, I wouldn't suggest it because of the amount of records you'd have. Defenatly use a text file or database.

Posting Permissions

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