• ini file size limit? (VBA Office2K)

    Author
    Topic
    #365100

    Is anyone aware of a limit on the size of an .ini file?

    I have one that keeps getting truncated while reading from
    the file using PrivateProfileString.

    The truncated file is 64K? Is that the limit?

    Viewing 4 reply threads
    Author
    Replies
    • #562576

      If I remember well, 64k is the limit of a Notepad file.
      If PrivateProfileString use Notepad in one or other way to access the .ini file ….

      The only other method i can think is a sequential reading of the file and analyse the line to find what your looking for.

      Dim TextLine
      Open "TESTFILE" For Input As #1    ' Open file.
      Do While Not EOF(1)    ' Loop until end of file.
          Line Input #1, TextLine    ' Read line into variable.
          Debug.Print TextLine    ' Print to the Immediate window.
      Loop
      Close #1    ' Close file.

      Hope this help

      • #562583

        I’d add that I’ve seen it recommended to use XML documents instead of ini files. You’ll need to reference the MSXML parser in your project. 2cents

    • #562609

      I doubt that there’s any limit.
      If you search your drives, you will find .ini files much larger than 64K included with some apps.

      Of course, that does not mean that VBA doesn’t have a bug, i.e., some poor programmer may have included a 64K buffer WITHIN VBA.

      If you can reproduce this with a simple example in VBA, I’d suggest trying the identical code in VB 6.

      If you don’t have VB 6, then export the VBA module to a .bas file. And create a .zip with the .bas .ini file. Email me the .zip and I’ll try it in VB 6.

    • #562647

      I don’t know for sure, but it seems much more likely that the limitation relates to the PrivateProfileString property, rather than the .ini file itself.

      At least based on the code samples in VBA Help and at the MS KB site, PrivateProfileString is designed for reading key values in sections of .ini files, rather than the entire file itself.

      Although I can’t speak from experience of having used it, it looks like the ReadAll method of the TextStream object (which is part of the FileSystemObject) might work to get around the size limitation.

      Gary

      • #562712

        The implication of the poster’s question would seem to be:

        1. PrivateProfileString is being used to read the stuff in a .ini. PrivateProfileString doesn’t read a file, just the individual name/value pairs.

        2. The .ini file is more than 64KB.

        Neither of the above should cause any problem.

        If there is a problem, I would expect:

        1. A bug in the implementation of PrivateProfileString, which I doubt, at least as far as accessing individual elements of a .ini.

        2. A botch in the implemenation of PrivateProfileString if a particular element happens to be more than 64KB bytes. Implementors sometimes do silly things such as ASSuME-ing what users “need”, rather than making the code more general, which is often faster and easier anyway.

        My offer to look at the .ini still stands, but expires at midnight today Eastern Standard Time in the USA.

    • #563015

      The problem is NOT with the size of the INI file itself.

      When using PrivateProfileString to read and write to an INI file the following limitations apply.
      1. The Windows API imposes a limit of 64KB on INI files. (it’s a Win3.X hold over issue)
      2. The text for each Key Value entry must be under 256 bytes.

      If you exceed the limits; for ‘Reads’, data beyond will be ignored and for ‘Writes’ data will be truncated.

      Your choices:
      1.You’ll have to write your own functions If you want similar read/write/create Key Value functionality of the PrivateprofileString for INI files larger than 64KB.
      2. Rethink what you are doing and find a better what to deal with the chunk of data your storing.
      3. Use the Windows Registry (don’t be scared… do it)
      4. Try splitting the INI info into several logical groups of KeyValues thereby having several smaller INI files.
      i.e. UserSettings.INI myAppSystem.INI Security.INI OtherStuff.INI

      Ohhh, and a side note. Not related to the 64KB+ problem but about using the PrivateProfileString API call in general. Be sure you pass everthing to the API using “ByVal”. Newbies cutting and pasting examples from the Web can get caught by examples that do not include the “ByVal” for variables passed to the API. Even older Microsoft Help Files had this error in their example of using PrivateProfileString API calls.

      Later,
      Bruce

    • #563440

      Re the 64K limit and reference4s to 256-byte key values.

      A few months ago i re-wrote my INI routines to handle values longer than 256bytes. I can dig those out if you are interested.; I suspect that the ones posted here (a few months ago) are out of date.

    Viewing 4 reply threads
    Reply To: ini file size limit? (VBA Office2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: