Results 1 to 13 of 13

Thread: [RESOLVED] Save Settings

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Resolved [RESOLVED] Save Settings

    Hi dears

    I want to save my settings (especially font style and labels position) I attached a simple project have ability to save and retriever it to project, but this method is difficult for big projects, and I am not able to save these settings in another and better method .... please reply me!


    Note:sorry for my bad English language



    Sincerely
    Mahmood Kh Pirani
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Save Settings

    App settings usually saved in INI file, search Google there are many ready to use INI classes

    There are to ways to save Font in INI file
    (1) One key for all font's properties (Recommended) e.g.
    Code:
    MainFont=Name|Size|Bold|Italic|Underline|Strikethrough
    Label1Font=Name|Size|Bold|Italic|Underline|Strikethrough
    Label2Font=Name|Size|Bold|Italic|Underline|Strikethrough
    Use Split function to rebuild font properties

    (2) One key for each font's property e.g.
    Code:
    MainFontName=Tahoma
    MainFontSize=12
    MainFontBold=1; 1 means Bold, 0 means Regular
    MainFontItalic=0
    MainFontUnderline=1
    MainFontStrikethrough=0
    Last edited by 4x2y; Apr 14th, 2017 at 05:26 PM.



  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Save Settings

    Quote Originally Posted by 4x2y View Post
    App settings usually saved in INI file, search Google there are many ready to use INI classes

    There are to ways to save Font in INI file
    (1) One key for all font's properties (Recommended) e.g.
    Code:
    MainFont=Name|Size|Bold|Italic|Underline|Strikethrough
    Label1Font=Name|Size|Bold|Italic|Underline|Strikethrough
    Label2Font=Name|Size|Bold|Italic|Underline|Strikethrough
    Use Split function to rebuild font properties

    (2) One key for each font's property e.g.
    Code:
    MainFontName=Tahoma
    MainFontSize=12
    MainFontBold=1; 1 means Bold, 0 means Regular
    MainFontItalic=0
    MainFontUnderline=1
    MainFontStrikethrough=0
    Can you send (attach!) this code in a simple project?

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Save Settings

    See the attached project.

    Ask here if you don't understand something.
    Attached Files Attached Files



  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Save Settings

    Quote Originally Posted by 4x2y View Post
    See the attached project.

    Ask here if you don't understand something.
    Many Thanks dear 4x2y

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [RESOLVED] Save Settings

    You can use IniFile class to save any setting you want with proper format you decide.
    For example to save any form location, size and window state, add the following two methods to IniFile class

    Code:
    Public Sub ReadFormPosition(ByVal strSectionName As String, ByVal strFileName As String, ByVal frm As Form, Optional ByVal blnReadSize As Boolean = True, Optional ByVal blnReadWindowState As Boolean = True)
        'Window state|Left|Top|Width|Height
        Dim strPos() As String
        
        strPos = Split(ReadValue(strSectionName, frm.Name & "Window", CStr(frm.WindowState) & "|" & CStr(frm.Left) & "|" & CStr(frm.Top) & "|" & CStr(frm.Width) & "|" & CStr(frm.Height), strFileName), "|")
        
        frm.Left = CSng(strPos(1))
        frm.Top = CSng(strPos(2))
        
        If blnReadSize Then
            frm.Width = CSng(strPos(3))
            frm.Height = CSng(strPos(4))
        End If
        
        If blnReadWindowState Then
            frm.WindowState = CInt(strPos(0))
        End If
    
    End Sub
    
    Public Sub WriteFormPosition(ByVal strSectionName As String, ByVal strFileName As String, ByVal frm As Form)
        'Window state|Left|Top|Width|Height
    
        If frm.Visible Then
            If frm.WindowState = vbNormal Then ' Write all properties
                WriteValue strSectionName, frm.Name & "Window", CStr(frm.WindowState) & "|" & CStr(frm.Left) & "|" & CStr(frm.Top) & "|" & CStr(frm.Width) & "|" & CStr(frm.Height), strFileName
            ElseIf frm.WindowState = vbMaximized Then 'Write only window state and preserve old size and location
                WriteValue strSectionName, frm.Name & "Window", CStr(frm.WindowState) & Mid$(ReadValue(strSectionName, frm.Name & "Window", "0|150|150|12000|90000", strFileName), 2), strFileName
            End If
        End If
    
    End Sub
    Usage:
    in any form use code like this
    Code:
    Private Sub Form_Load()
        cINI.ReadFormPosition "SectionName", mstrSettingFile, Me
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        cINI.WriteFormPosition "SectionName", mstrSettingFile, Me
    End Sub



  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: [RESOLVED] Save Settings

    Quote Originally Posted by 4x2y View Post
    You can use IniFile class to save any setting you want with proper format you decide.
    For example to save any form location, size and window state, add the following two methods to IniFile class

    Code:
    Public Sub ReadFormPosition(ByVal strSectionName As String, ByVal strFileName As String, ByVal frm As Form, Optional ByVal blnReadSize As Boolean = True, Optional ByVal blnReadWindowState As Boolean = True)
        'Window state|Left|Top|Width|Height
        Dim strPos() As String
        
        strPos = Split(ReadValue(strSectionName, frm.Name & "Window", CStr(frm.WindowState) & "|" & CStr(frm.Left) & "|" & CStr(frm.Top) & "|" & CStr(frm.Width) & "|" & CStr(frm.Height), strFileName), "|")
        
        frm.Left = CSng(strPos(1))
        frm.Top = CSng(strPos(2))
        
        If blnReadSize Then
            frm.Width = CSng(strPos(3))
            frm.Height = CSng(strPos(4))
        End If
        
        If blnReadWindowState Then
            frm.WindowState = CInt(strPos(0))
        End If
    
    End Sub
    
    Public Sub WriteFormPosition(ByVal strSectionName As String, ByVal strFileName As String, ByVal frm As Form)
        'Window state|Left|Top|Width|Height
    
        If frm.Visible Then
            If frm.WindowState = vbNormal Then ' Write all properties
                WriteValue strSectionName, frm.Name & "Window", CStr(frm.WindowState) & "|" & CStr(frm.Left) & "|" & CStr(frm.Top) & "|" & CStr(frm.Width) & "|" & CStr(frm.Height), strFileName
            ElseIf frm.WindowState = vbMaximized Then 'Write only window state and preserve old size and location
                WriteValue strSectionName, frm.Name & "Window", CStr(frm.WindowState) & Mid$(ReadValue(strSectionName, frm.Name & "Window", "0|150|150|12000|90000", strFileName), 2), strFileName
            End If
        End If
    
    End Sub
    Usage:
    in any form use code like this
    Code:
    Private Sub Form_Load()
        cINI.ReadFormPosition "SectionName", mstrSettingFile, Me
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        cINI.WriteFormPosition "SectionName", mstrSettingFile, Me
    End Sub


    Thank you dear 4x2y for this nice codes, I'm new in programming therefore I don't understand codes like this. These codes are very complicate for me and I couldn't use it in my project (I didn't understand how to use it) . . . But however Many thanks for codes you are very kind

    Sincerely
    Mahmood Kh Pirani

  8. #8
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: [RESOLVED] Save Settings

    To use IniFile class with any project you have:
    (1) Open your project with VB6 IDE
    (2) Go to Project menu, select Add Class Module, select Existing tab and browse for IniFile.cls

    Now you already know how to use it from above sample project.



  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] Save Settings

    I know that, to a large degree, this is a matter of personal taste. But personally, I'd only create an INI file as a last resort. As with many cases, this is a matter of understanding the scope and lifetime of the data you wish to save.

    In another thread, I recently outlined my view on scope and lifetime of various data. That can be found here. You'll notice that any mention of an INI file is the last bullet-point on my list.

    Best Regards,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Save Settings

    @Elroy. Externally persisted settings (INI, db, txt, etc) are often easier to migrate than those saved in the registry. That is an advantage if it applies. If moderate security is needed, both internal/external, encoding can be considered.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] Save Settings

    @LaVolpe: I suppose you're correct, but it does often come down to the scope (and lifetime) I'm after. For me, sure, I've got a database, and there are tables in it specifically for storing all kinds of settings.

    However, this is also a multi-user program (all using a common database). For instance, the first screen that comes up shows the patient list. And I like to have it "default" to the last patient that was being examined. But ... this "last patient" will be different depending on whose workstation is being used, and also who's logged into a particular workstation. Therefore, this is a perfect scenario for making use of the registry.

    I must admit that I use all combinations of that list I linked to in the other thread. It truly just depends on the scope and lifetime I'm after. There's only one place where I actually make use of an INI file, but I won't outline it here. In all other cases, stuffing settings in the database or stuffing them into the registry works ideally.

    And yes, regarding migration, which occasionally happens when a file server is replaced, all the settings at that level are best stuffed into the database.

    Best Regards,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Save Settings

    External settings are usually best in my work. We have workstations and servers that are replaced every few years. Vast majority of app settings were ini/config based. This made it easy to transfer to new equipment. The more recently developed apps use an SQL database and that database is exported and uploaded on the new equipment as needed. However, the database location/ip and connection information is stored externally to file. Being government and high system turnover/upgrades, along with restricted user rights, the external settings work best for us.

    Edited: A nightmare scenario shortly after I was hired. We upgraded and replaced some servers. Several compiled, homegrown applications were hardcoded with the server name they connected to (no source code remained). Well, that server was gone and new one set up using a different naming convention. So fortunate they were written in VB and I could find their text in the executable. Even more luck... the new server name was bigger than the old, but the old server name was just longer than the new server's IP address. I just "hacked the exe" and overwrote the old server name with the new server's IP (adding a leading zero or two to fill out the space) and presto: up & running within a short time. Those apps have since been rewritten. I think we can all agree that the worst place to store settings (that could possibly change) is within the app itself
    Last edited by LaVolpe; Apr 17th, 2017 at 06:47 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: [RESOLVED] Save Settings

    Quote Originally Posted by LaVolpe View Post
    I think we can all agree that the worst place to store settings (that could possibly change) is within the app itself
    hahaha, yes, on THAT we absolutely agree.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Tags for this Thread

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