Results 1 to 27 of 27

Thread: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,488

    Resolved [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    My programs have made use of a settings.ini file and I have used GetPrivateProfileString and WritePrivateProfileString APIs to read/write as I need. I have been using that code for years and it served me well.

    Previously I plonked the settings in the registry (now deprecated) or within a settings.ini in the program folder. I am now putting them in a a settings.ini within users/user/appdata/roaming/applicationFolder

    I realise that using a settings.ini seems to be deprecated as an idea, and I should be using xml, xaml or json. I always found the settings.ini to be easy to implement, the XML a pain to read/write in code and whilst I do have a little experience of json from my javascript time, it just seems like overkill for a few values in a settings file.

    The reason I am asking is that I have unveiled a (known) bug in GetPrivateProfileString and WritePrivateProfileString that occurs when I have been writing encrypted strings to stored variables in a INI file. Those APIs are fine when writing ANSI chars but seem to throw a random wobbly when handling some of the characters that result from my encryption code. Sometimes they worked but other times the string was read back or written with extra unwanted chars.

    I have already written two routines to replace those APIs for reading/writing INI data but I do realise that when an API can't handle your data it may be time to move on.

    My question is - The best alternative to a settings.ini file, what do you use, JSON, XML, anything else? Any pitfalls?
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,168

    Re: VB6: Question - best alternative to a settings.ini file?

    Still using INI file format, using my own classes for creating, reading, writing
    So easy to do manual changes using whatever text editor

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,931

    Re: VB6: Question - best alternative to a settings.ini file?

    I'm still using .ini files in legacy projects but transitioning everything to .conf in JSON format like this -- it just feels better (besides being heirarchical).

    cheers,
    </wqw>

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,856

    Re: VB6: Question - best alternative to a settings.ini file?

    Personally, I'd think that GetSetting/SaveSetting would be the correct alternative.

    However, truth be told, I use both. And I also stuff the great majority of my settings in my actual database.

    So, I use three different approaches:
    1) GetSetting/SaveSetting.
    2) GetPrivateProfileString/WritePrivateProfileString.
    3) Written into my database.

    Why all three? Well, #1 goes into the machine's registry, so it's specific to that machine, and my application is typically executed from (and has its database on) a network drive. So, anything saved that way will be specific to that user.

    #3 is the most useful for me, and the one I use most often. However, by default, and in 99% of the cases, my database (an MDB file) resides in the same (network) folder as the executable. So, with that configuration, there's no problem finding the database. However, under certain circumstances, a user will want the program on their local drive (specifically in the case where they're connected to the network via WiFi). In those cases, I need to have some way for them to find the database.

    And, in those cases, I use #2 (an INI file). I specifically like an INI file because it's easy for the user to "see" the path where their database should be located (by calling up the INI file in Notepad).

    -----

    So, personally, I find application for all the approaches. Actually, I also make extensive use of the ...\AppData\Local\Temp folder, but that's only for temporary files.
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5
    Frenzied Member
    Join Date
    Dec 2012
    Posts
    1,240

    Re: VB6: Question - best alternative to a settings.ini file?

    I haven't used an "ini" file for ages. I find it faster, simpler, and easier to use the registry. It is a little more difficult for service programs, because they have to use the system area of the registry.

    J.A. Coutts

  6. #6
    Addicted Member jg.sa's Avatar
    Join Date
    Nov 2017
    Location
    South Australia ( SA )
    Posts
    164

    Re: VB6: Question - best alternative to a settings.ini file?

    G'Day yereverluvinuncleber

    Quote Originally Posted by yereverluvinuncleber View Post
    I realise that using a settings.ini seems to be deprecated as an idea, and I should be using xml, xaml or json. I always found the settings.ini to be easy to implement, the XML a pain to read/write in code and whilst I do have a little experience of json from my javascript time, it just seems like overkill for a few values in a settings file.
    In my humble option it is not a gr8 idea to stop doing what u r doing

    Quote Originally Posted by yereverluvinuncleber View Post
    The reason I am asking is that I have unveiled a (known) bug in GetPrivateProfileString and WritePrivateProfileString that occurs when I have been writing encrypted strings to stored variables in a INI file. Those APIs are fine when writing ANSI chars but seem to throw a random wobbly when handling some of the characters that result from my encryption code. Sometimes they worked but other times the string was read back or written with extra unwanted chars.
    I have been down that rabbit hole, I always tokonize any 'binary' ( non STD chars. ) so something like asc(strValue) and make allowances for 99 and 999 value by adding a '0' + 99 and a data stru. %20%999%20%999 etc.

    Go to immediate window and try this

    Debug.Print Asc("A")
    Debug.Print Chr(065)

    So you have a long value and you might run into another M$ bug, .ini files have a limit !!!

    Quote Originally Posted by yereverluvinuncleber View Post
    My question is - The best alternative to a settings.ini file, what do you use, JSON, XML, anything else? Any pitfalls?
    Dont change, abstract
    Last edited by jg.sa; Jan 2nd, 2022 at 10:59 AM.

  7. #7
    Fanatic Member
    Join Date
    Jun 2015
    Posts
    714

    Re: VB6: Question - best alternative to a settings.ini file?

    If only a handful of settings I just use getsetting/save setting for larger or more complex things I usually dump a udt to disk

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,488

    Re: VB6: Question - best alternative to a settings.ini file?

    Thankyou, your feedback appreciated. I will stick to the INI file for the time being.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,083

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    I use ini files more often than not. In the event that would not do then I either use a database or my own custom rolled file, either with a UDT and RA, a variable binary file or just a plain old text file depending on the needs. Ini files are simple and work in most cases where you only need to store a small amount of data.

  10. #10
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,067

    Re: VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by yereverluvinuncleber View Post
    Thankyou, your feedback appreciated. I will stick to the INI file for the time being.
    And use Base64 encoding/decoding to handle non-Ansi data.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    23,466

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Base64 isn't very hand-editable stuff, and hand-editing is the main reson to use any text serialization format anyway. If you don't require manual fiddling you could just use a PropertyBag, which provides its own serialization format.

    There are many possibilities, and choosing among them depends on the requiremnts. There is no ideal format that replaces all others. JSON for example has some particularly nasty baggage that gets heavy or problematic in some scenarios while being ideal in others.

  12. #12
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,067

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Yes, a property bag is another option, but if he already has code to save to an INI file, perhaps it is simpler just to save the binary data as Base64.

  13. #13
    Lively Member
    Join Date
    Feb 2015
    Posts
    92

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    I use a binary file along with an app specific UDT for the data. It also has built-in file validation via writing/reading a small header in the file, so if the file is missing, empty or corrupt then default settings are used.

    I quickly put this together to illustrate:

    Code:
    Option Explicit
    
    '- In a module
    
    Type LdSetup
     '- Anything can be here
     Value1 As Long
     Value2 As Long
     Value3 As Long
     '-------
     String1 as String
     String2 as String
    String3 as String
     '- ETC.....
    End Type
    
    Public LGDSettings As LdSetup
    
    Const strHeader = "79*79" '- Unique file header
    
    
    
    '- Save Setup data
    Public Sub SaveSettings()
      
      Dim ff As Integer
           
       
        ff = FreeFile
        Open App.path & "\LDSettings.stg" For Binary As #ff
          Put #ff, 1, strHeader '- Write header
          Put #ff, , LGDSettings '- Write settings
        Close #ff
        ff = 0
    
    End Sub
    
    
    '- Load Settings data
    Public Sub LoadSettings()
      
      Dim ff As Integer
      Dim flHeader As String
      
      '- No data file so bail out
      If Dir(App.path & "\LDSettings.stg") = 0 Then Exit Sub
      
      '- Pad header to 5 bytes
      flHeader = Space$(5)
      '- Get available file number
      ff = FreeFile
         '- Open data file & get data
         Open App.path & "\LDSettings.stg" For Binary As #ff
          Get #ff, 1, flHeader
          Get #ff, , LGDSettings
         Close #ff
         
         '- Check for correct header data
         '- and take appropriate action
        If flHeader <> strHeader Then
        
         Kill App.path & "\LDSettings.stg"
        
        
    '-- Set Defaults
        
         Dim fG As Integer
        
        
        With LGDSettings
          
        .Value1 = 10
        .Value2 = 77
        .Value3 = 0
    '---
        .String1 = ""
        .String2 = "String2 Value" 
        .String3 = "SomeWords"
        End With
      
      End If
        
    End Sub
    Happy new year, hope this helps!

    EDIT: Fixed some small details
    Last edited by SomeYguy; Jan 2nd, 2022 at 03:38 PM.

  14. #14
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,931

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Saving your settings in binary (UDT of propbag) prevents users from manually modifying config when you app hangs on startup.

    Another caveat is that you don't have to implement a settings dialog at all when you config is text file based or can include undocumented settings which can be tweaked only manually.

    cheers,
    </wqw>

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,488

    Re: VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by Eduardo- View Post
    And use Base64 encoding/decoding to handle non-Ansi data.
    I just added that and it does help with the special chars.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  16. #16
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,856

    Re: VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by Eduardo- View Post
    And use Base64 encoding/decoding to handle non-Ansi data.
    Yeah, I was going to say that that sort of defeats the purpose of an INI file. For me, the primary reason I'd consider one is so that a naïve user could view it and possibly edit it with Notepad. Once that ability is gone (such as some kind of encoding of the data), I'd tend to gravitate toward the registry or some other method of storage, with most other alternatives able to handle full Unicode.

    But I think most of that has already been said.

    Also, stuffing this stuff in the registry almost assures the user won't tamper with it.
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  17. #17
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,067

    Re: VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by Elroy View Post
    Yeah, I was going to say that that sort of defeats the purpose of an INI file. For me, the primary reason I'd consider one is so that a naïve user could view it and possibly edit it with Notepad. Once that ability is gone (such as some kind of encoding of the data), I'd tend to gravitate toward the registry or some other method of storage, with most other alternatives able to handle full Unicode.

    But I think most of that has already been said.

    Also, stuffing this stuff in the registry almost assures the user won't tamper with it.
    I don't think that the purpose of using INI files are always to allow the user to edit the data. Most users don't have a clue about those things anyway.

    And reading to OP, the data is already non-editable:

    Quote Originally Posted by yereverluvinuncleber View Post
    The reason I am asking is that I have unveiled a (known) bug in GetPrivateProfileString and WritePrivateProfileString that occurs when I have been writing encrypted strings to stored variables in a INI file. Those APIs are fine when writing ANSI chars but seem to throw a random wobbly when handling some of the characters that result from my encryption code. Sometimes they worked but other times the string was read back or written with extra unwanted chars.

  18. #18
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,856

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Hey, if he wants an INI file, then go for it.
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  19. #19
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,067

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by Elroy View Post
    Hey, if he wants an INI file, then go for it.
    I think there was a trend to use INI files instead of the registry, because the idea was not to pollute the registry with lot of entries.
    May be that's the reason.
    My personal opinion is that if you are not going to store much data, the registry is handy (we have the ready-to-use Get/Set/DeleteSetting functions in VB).

  20. #20
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,856

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    I've gone back and forth about the registry through the years. Personally, in my huge application, I probably use it in maybe 20 places. Basically, I use it when I want user-specific things stored, and it's just some quirky setting. For instance, I have a listbox (actually a ListView) that shows a patient list. But certain patients are "closed". Some users like to see those while others don't. That's a registry setting for me.

    But, when Windows 32-bit came out, I think the registry was intended to replace all the INI files.

    In the past, I have often worried about how "polluted" my registry was getting (not from me, but from all the other crud I have installed). I used to try and keep it clean, taking snapshots and running "cleaners". However, somewhere along the way, I just quit worrying about it.

    Apparently, however Windows manages the registry, it must be quite fast and efficient, because my registry is full of all kinds of crud, and it seems to work just fine.

    EDIT: It makes me think about how (in the DOS days) I used to insist on knowing the purpose of every file on my computer. When Windows 3.1 came out, I tried to do the same thing (and actually accomplished it for a while). However, somewhere along the way, it just got to be too much work. These days, I probably couldn't tell you the specifics of more than 10% of the files on my computer (if that). (I don't mean something as trivial as "this file goes with this program". I mean, "this file is used by this program, and that program needs it because ...") The registry has very much become the same way.
    Last edited by Elroy; Jan 2nd, 2022 at 08:20 PM.
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  21. #21
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,067

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    I use the registry. But don't store much, just some simple program settings (most of the times).

    In one program I made a replacement for GetSetting/SaveSetting/DeleteSetting that according to a global variable it uses the registry or otherwise an INI file.

    I'm thinking of revisiting that code and publishing it in the Codebank. It is quite simple anyway.
    But not right now...

  22. #22
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    7,856

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by Eduardo- View Post
    I use the registry. But don't store much, just some simple program settings (most of the times).
    Sounds like we're in agreement on that one.

    I'd never dream of trying to use it to store "live" data, or as any kind of database.

    I do have procedures that go beyond the GetSetting/SaveSetting area of the registry. There's one instance where I have to change a registry setting that was set by another program. It's actually a PDF print driver, and I just change the default folder where it's to save the PDF file. It's just a convenience for the user so they don't have to navigate with the Save dialog.
    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. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,488

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    The problem I have found with the registry is that if your app details are in the wrong place and Windows doesn't want you, nor another program to edit that data any more then you may have a problem. I have a program from a 3rd party that allowed user access to its registry settings. Later versions of Windows seem to allow you to make changes but they don't actually 'stick'. You are modifying a shadow copy of the registry data. No errors, nothing, the changes just don't take place.

    As I understood it, the use of settings.ini harked back to the days of DOS and beyond and was still in use when Win 3.11 and '95 provided the registry - when it became the recommended method for applications and user details. Then at some point Microsoft stopped recommending the registry as a location for general user settings (probably due to slow startup times with a full and massive registry) and they seemed to be directing users towards configuration files stored under users/user/appdata/local or roaming.

    In one of my programs I use the registry or settings.ini and in my latest programs I store all under appdata. For ease of modification and ease of coding I tend to use ini files and the Win APIs that provide keyed access to the data. My problem with the APIs not handling some of the special chars in the encrypted password has been alleviated with the recommendation to use base64 encoding before saving.

    So, I am back with the settings.ini as my preferred option, as the majority here seem to confirm that it is the best approach. I don't need hierarchical storage, it is only used as startup for configuration, so anything else might be overkill. I thank you for your assistance.
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  24. #24
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,931

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by Eduardo- View Post
    I think there was a trend to use INI files instead of the registry, because the idea was not to pollute the registry with lot of entries.
    The "recent" trend with ini/conf files is about making apps portable.

    The end user has to be able to "install" the app on a USB drive and use it from there on different PCs being able to transfer settings seamlessly.

    cheers,
    </wqw>

  25. #25
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,067

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    Quote Originally Posted by wqweto View Post
    The "recent" trend with ini/conf files is about making apps portable.

    The end user has to be able to "install" the app on a USB drive and use it from there on different PCs being able to transfer settings seamlessly.

    cheers,
    </wqw>
    Yes, that was my motivation in my program. I detect if it is installed in Program files, if so then I use the registry, otherwise I use an INI file.

  26. #26
    Addicted Member jg.sa's Avatar
    Join Date
    Nov 2017
    Location
    South Australia ( SA )
    Posts
    164

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    G'Day yereverluvinuncleber

    Because our app. templates were set in stone in the '80s we have always created a folder in the root and everything is 'configured' under there, notice I didn't say 'setup' because we don't have a setup program, we found when we stood up on the first M$ domain joined PC that this worked really well and we were glad we had not got into persistent via reg. When a different user logs in we had no need to 'copy' reg. entries etc. etc. etc.

    We reg. for a call back for any attempt to open a .ini under this root folder and have an app. sasIniED to edit these .inis, this app. has all the business rules and manages the editing or not editing of binary data as well as normal 'text' - Job done

    A down stream of this approach is if the user click on a .ini in M$ folders etc. Notepad fires up as expected

    Quote Originally Posted by yereverluvinuncleber View Post
    the use of settings.ini harked back to the days of DOS and beyond
    100% agree

    Quote Originally Posted by yereverluvinuncleber View Post
    I don't need hierarchical storage
    You can do this with .ini, just normalise away

  27. #27

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    1,488

    Re: [RESOLVED] VB6: Question - best alternative to a settings.ini file?

    up to 32k? - I should never need more than this...
    By the power invested in me, all the threads I start are Niya and Olaf free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

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