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?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » ini file size limit? (VBA Office2K)
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
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.
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
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.
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
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications