Results 1 to 16 of 16

Thread: Check this Module out, if you understand it then you will use it (-:

  1. #1

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Check this Module out, if you understand it then you will use it (-:

    Dear all,
    i used to write a lot of code inside my forms inside the load event and in the closing event. i used to write this code because i wanted my software to remember last user settings. in other words i wanted the software to remeber for each form in the system where did you user positined last time, what item he was selecting in the listbox. which radio button selection, which tabpage is viewed in the tabcontrol , which last dates are selected in the datetime picker and other settings. i usually wanted the user to open the form exactly as the last time he closed it.

    it was too hard and i did a lot of coding on each forms. i missed some controls on the hurry or i was too lazzy to write codes for them.


    Moreover i used to save the settings in the registery, jmcilhinney and i was discussing in a thread and he pointed out that saving settings in the registery is a bad practice because it is considered now the bottleneck for performance in windows os. Moreover there was no easy way that my user can move his settings along on multiple pcs. (export and import registery keys is very pain in the face ).

    so , i decided to write a module to do it for me, save all the possible settings regardless what controls are placed on the form and regardless if they are nested or not.

    as a result of several hours of working today i managed to produce this class.

    it is called formsettings

    it has two public functions that developer would like to use
    saveform and loadtoform

    you can use it like this

    VB Code:
    1. 'To save form settings
    2.   Dim x As New FormSettings
    3.   x.SaveForm(Me)
    4.  
    5. 'to load settings into form
    6.         Dim x As New FormSettings
    7.         x.LoadtoForm(Me)


    this class saves the settings into one xml file called "settings.xml", it is placed in the root directory of the application and can be moved to transfer settings between computers.

    also i made some adjustements to the control,
    1 - during the saving or loading process if you want to ignore a certain control on the form, just set its tag to "dontsave" in design or runtime.
    My Class will ignore it on the sweep

    2 - If you want to choose certain types of controls to be saved and loaded, you will have a set of public variables as following in the class

    '''''''''''
    'Setting Parameters
    Public FormSize As Boolean = True
    Public FormPosition As Boolean = True
    Public ListBoxes As Boolean = True
    Public ComboBoxes As Boolean = True
    Public DatetimePickers As Boolean = True
    Public TabControls As Boolean = True
    Public RadioButtons As Boolean = True
    Public CheckBoxes As Boolean = True
    Public TextBoxes As Boolean = False
    '''''''''''

    Each of this variables enables or disables the sweep for it's control types and all controls that inherits from this type , Thx to kleinma he helped me in the inheritance part.

    good luck all and i wish you can use it in your software easily. Please keep me posted if anybody upgrades my code as i may need the modifications to use myself.


    please post me your opinions

    rgds

    PS: the class file is attached with the thread
    Attached Files Attached Files

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Check this Module out, if you understand it then you will use it (-:

    It's really good, and great
    Thanks
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Check this Module out, if you understand it then you will use it (-:

    That's pretty good, I would have gone with XML files myself.

    I'm assuming this is for 1.1? Because VB 2.0 has "My.Settings".

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Check this Module out, if you understand it then you will use it (-:

    Quote Originally Posted by mendhak
    I'm assuming this is for 1.1? Because VB 2.0 has "My.Settings".
    It's ready code, I'll use it for both. it really is great
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Check this Module out, if you understand it then you will use it (-:

    Quote Originally Posted by mendhak
    That's pretty good, I would have gone with XML files myself.

    I'm assuming this is for 1.1? Because VB 2.0 has "My.Settings".

    It looks like it is XML, so what are you seeing?

    Personally, I would have used binary serialization, since it is a class, and therefore amenable to that. That would create a fast and small file.

    I've never had a need to do something like this, but I certainly applaud the approach. Encapsulating functionality into a stand-alone class like this is the very ideal of OO.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Check this Module out, if you understand it then you will use it (-:

    thank you all for your replies, i know it can be little modified for more performance. and that i will do when i have some spare time.

    also regarding the serialization process, i agree serialization is fast and lighter but xml files can be even modified throught text editor.

    so this setting file can be edited with custom settings from outside the software.

    anyway i am glad you agree on my work

    rgds

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Check this Module out, if you understand it then you will use it (-:

    What about XML Serialization? That's what I do.

    BTW, I haven't had time to look through your Module but I assume you just enumerate through the Controls within the form and save their name and data? If that's the case, wouldn't that not include any private controls (which is default in VB)?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  8. #8
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Re: Check this Module out, if you understand it then you will use it (-:

    Nice, thanks.
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

  9. #9

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Check this Module out, if you understand it then you will use it (-:

    If that's the case, wouldn't that not include any private controls (which is default in VB)?
    i dont understand what u mean, can u explain more

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Check this Module out, if you understand it then you will use it (-:

    Quote Originally Posted by maged
    i dont understand what u mean, can u explain more
    You have Public and Private variables. Public can be seen and accessed by anything but Private can only be accessed within that class it's declared it. Most controls you use are automatically set as Private.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  11. #11

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Check this Module out, if you understand it then you will use it (-:

    ah i got u now,

    the point of this class is to be declared inside the form itself, this way it will automatically has access to all controls - including private controls -

    right ?
    Last edited by maged; Jun 1st, 2006 at 08:50 AM.

  12. #12

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Check this Module out, if you understand it then you will use it (-:

    if you are using a base form inside your project and inherits from it to all other your application form, then it wont be a problem.

    just declare the class inside the base form and it will work along all inherited forms

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Check this Module out, if you understand it then you will use it (-:

    Quote Originally Posted by kasracer
    If that's the case, wouldn't that not include any private controls (which is default in VB)?
    since when are controls in VB declared private by default??? Last time I looked they get declared friend when you add a control to a form.

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Check this Module out, if you understand it then you will use it (-:

    Quote Originally Posted by Shaggy Hiker
    It looks like it is XML, so what are you seeing?
    Intonation, my dear hiker, intonation.

  15. #15
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Check this Module out, if you understand it then you will use it (-:

    Quote Originally Posted by maged
    the point of this class is to be declared inside the form itself, this way it will automatically has access to all controls - including private controls -

    right ?
    Yup. For some reason I was thinking it would be declared outside the Form.

    Nifty
    Quote Originally Posted by kleinma
    since when are controls in VB declared private by default??? Last time I looked they get declared friend when you add a control to a form.
    Oh my bad. I'm used to C#
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  16. #16

    Thread Starter
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Check this Module out, if you understand it then you will use it (-:

    Intonation
    what do u mean by this mendhak, sorry but my mother tongue is not english

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