Results 1 to 9 of 9

Thread: Thingamajig in the whatchamacallit.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95

    Thingamajig in the whatchamacallit.

    Yeah, this is going to sound really stupid, but what's the best way to save program settings in order to reload on the next launch? Like when a user selects a folder to download to, should I stash that in the registry or something and when is the best time to load that on the next program startup? On the form load or main or what?

    Take it easy on me I've been up all night.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Dear KT3, I'm working just around the same problem. I'm a beginner and think many friends of this forum will give you better ideas, anyway, this is mine:

    When setting form is loaded, it tries to read a particular file:
    "C:\AEASRL\GIN\INIGIN.TXT"

    If an error occurs, an Array is filled with default values, otherwise it is filled with the values found in the file.

    Obviously. there is code to manipulate these values.

    Then, when the form is closing, the user can choose if save or not the last changes, if any

    The File is a text file written by a STREAMWRITER and read by a STREAMREADER

    Any row contains a paramether name and value.

    The first 30 characters (fixed lenght) is for the name. If it's shorter, I use padright method to reach the lenght with the right number of spaces.

    This is the basic idea. I'm testing and debugging it just now. It seems work fine, but I need more time to sentence it!

    Excuse my english. Hope to be useful.

    Live long and prosper (Mr. Spock)

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    You can write the settings to the registry.
    Then read them from it everytime the application is launched.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    Alright! I think I might just do that.


    ...

    So, umm.. How do I do that? I mean, I'm pretty sure I can figure out how to access the registry on my own, but I need to get the path to the user's desktop to enable that as the default download location unless an alternate selected location is found by reading the registry.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    Alex, thanks for the help, man, but I think if you were going to just do that, wouldn't you be better off using the application configuration file? Either way, I'd much rather use the registry, because it makes it more transparent to the user. For this application anyway. For tools and stuff I might want to use an .ini file because I know people like me love to be able to move those tools to other PCs and keep all their settings without backing up the damn registry keys.
    Last edited by Kt3; Apr 25th, 2004 at 02:41 PM.

  6. #6
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Dear KT3, thanks for the suggest, I will have a look to the application configuration file. At the moment I don't know which kind of animal it was
    To write in the register is perhaps the best way for someone advanced.
    Anyway I prefer don't put my inexpert hands in shared files. I don't want to risk to do something wrong in files that other applications need. I want to be sure, like was in the ancient DOS applications, that you can cancel all traces of my applications only quickly deleting one or two folders. But that is only my personal point of view.
    Live long and prosper (Mr. Spock)

  7. #7
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Registry? Yuck how late 90's is that?

    What I always do is write a serializable class / structure that contains all settings for the app and then save / load a binary file. Fast, efficient, incomprehensible to (my) fellow programmers thus ensuring job security
    I don't live here any more.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    Originally posted by wossname
    Registry? Yuck how late 90's is that?

    What I always do is write a serializable class / structure that contains all settings for the app and then save / load a binary file. Fast, efficient, incomprehensible to (my) fellow programmers thus ensuring job security

    Oh you ba*tard!

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95
    Ok, I did it. I made a serializable class to hold all configuration information. Aren't you proud?

    Documenting it for those that care. This is the serializable class that contains a Download property which sets or returns a string containing the user specified download folder path.

    VB Code:
    1. <Serializable()> _
    2. Public Class Configuration
    3.  
    4.     Private _SelectedPath As String
    5.  
    6.     Public Property Download() As String
    7.         Get
    8.             Return _SelectedPath
    9.         End Get
    10.         Set(ByVal Value As String)
    11.             _SelectedPath = Value
    12.         End Set
    13.     End Property
    14.  
    15.  
    16. End Class

    Here is how it is access on startup:

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         mainBar.Visible = False
    4.         Try
    5.             Dim fs As New FileStream("snlv2.dat", FileMode.Open)
    6.             Dim r As New StreamReader(fs)
    7.             Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    8.  
    9.             config = CType(formatter.Deserialize(fs), Configuration)
    10.             saveTo.SelectedPath = config.Download
    11.  
    12.             r.Close()
    13.             fs.Close()
    14.  
    15.         Catch ex As System.IO.FileNotFoundException
    16.  
    17.         End Try
    18.  
    19.  
    20.     End Sub

    In my application, when a user clicks this button:

    VB Code:
    1. Private Sub configDownload_Click(ByVal sender As System.Object, ByVal e As C1.Win.C1Command.ClickEventArgs) Handles configDownload.Click
    2.  
    3.         SaveDownloadLocation()
    4.  
    5.     End Sub

    It calls the SaveDownloadLocation routine, which runs this code. saveTo is an instance of the System.Windows.Forms.FolderBrowserDialog object.

    VB Code:
    1. Private Sub SaveDownloadLocation()
    2.  
    3.         saveTo.ShowDialog()
    4.  
    5.         config.Download = saveTo.SelectedPath
    6.  
    7.         Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    8.         Dim fs As New FileStream("snlv2.dat", FileMode.Create)
    9.         formatter.Serialize(fs, config)
    10.         fs.Close()
    11.  
    12.     End Sub

    In my software I have a listview that has a list of downloadable files. On a doubleclick event, besides trapping the item under the mouse in the listview, it also checks to see if saveTo.SelectedPath is an empty string. If so, it calls the SaveDownloadLocation() method to allow the user to specify a download location first, in case that hasn't been done. Of course, if the user has previously specified a download location and wishes to change the location, there is a button on the toolbar which will do this, the configDownload command, and its event is handled as shown above.

    I also caught an exception in my download method so that if the selected path is invalid, i.e. the folder doesn't exist, it calls the SaveDownloadLocation() routine.

    And, you're probably thinking, "who's this wise guy who thinks he knows it all? Strolling in here onto our forums documenting some piece of crap application he wrote like we care? "

    I'm KT, 20 years old, and I've only been learning to code in VB.NET and some C#, PHP, Perl and Python for only one month. I don't have any other programming experience besides that.

    Peace,

    KT

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