PrivateProfileString character limit

D

D

I haven't been able to find any information on this, so I thought I'd ask in
here and see if anyone knows. Does the System.PrivateProfileString bit have
a limit of 255 characters per entry? Something in a procedure I am running
is limiting me to 255 characters, and I don't think it's the array defined as
string, or the listboxes/textboxes, so I'm guessing it's the .ini file I'm
storing info in. Thanks a lot.
 
W

Word Heretic

G'day "D" <[email protected]>,

VBA string creation is limited to 255.

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


D reckoned:
 
J

JB

Word said:
G'day "D" <[email protected]>,

VBA string creation is limited to 255.

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


D reckoned:
Steve is there a way round that?
 
M

Martin Seelhofer

Hi JB
Steve is there a way round that?

Sure, write your own PrivateProfileString-function (which
istn't that hard), e.g.:


Function getIniString(file As String, section As String, key As String)
Dim nr As Long
Dim curLine As String

nr = FreeFile

Open file For Input As nr
' read until section is found
Do Until EOF(nr) Or LCase(curLine) = "[" & LCase(section) & "]"
Line Input #nr, curLine
Loop

' read until end of file or key is found
Do Until EOF(nr)
Line Input #nr, curLine
' key found?
If LCase(curLine) Like LCase(key) & "=*" Then
' yes -> outta here
getIniString = Mid(curLine, Len(key) + 2)
Exit Do
End If
Loop
Close nr
End Function


Cheers,
Martin
 
M

Martin Seelhofer

Hello again

By the way, those 255 characters seem to me to be a limit of the
C-API-function GetPrivateProfileString (Kernel32) - from which
System.PrivateProfileString probably makes use of - and not of
VBA itself...


Cheers,
Martin
 
J

JB

Martin said:
Hi JB

Steve is there a way round that?


Sure, write your own PrivateProfileString-function (which
istn't that hard), e.g.:


Function getIniString(file As String, section As String, key As String)
Dim nr As Long
Dim curLine As String

nr = FreeFile

Open file For Input As nr
' read until section is found
Do Until EOF(nr) Or LCase(curLine) = "[" & LCase(section) & "]"
Line Input #nr, curLine
Loop

' read until end of file or key is found
Do Until EOF(nr)
Line Input #nr, curLine
' key found?
If LCase(curLine) Like LCase(key) & "=*" Then
' yes -> outta here
getIniString = Mid(curLine, Len(key) + 2)
Exit Do
End If
Loop
Close nr
End Function


Cheers,
Martin
Ahh Cheers Martin, Never thought of doing that :)

J
 
W

Word Heretic

G'day "Martin Seelhofer" <[email protected]>,

Write a loop and concat a string mate...

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Martin Seelhofer reckoned:
 
D

D

From what I can tell, it is a limit of the privatprofilestring function, so
what I have done now is written a routine to break up/put together any
entries longer than 255 characters, and store them as separate entries in the
..ini file. The array I'm pulling this info into is declared As String, and
it is having no problem holding the long entries, so I"m wondering if I have
misunderstood your comment regarding string length?
 
D

D

I initially thought about doing something like that, but I came into problems
with trying to figure out how to edit entries or create new entries.

Martin Seelhofer said:
Hi JB
Steve is there a way round that?

Sure, write your own PrivateProfileString-function (which
istn't that hard), e.g.:


Function getIniString(file As String, section As String, key As String)
Dim nr As Long
Dim curLine As String

nr = FreeFile

Open file For Input As nr
' read until section is found
Do Until EOF(nr) Or LCase(curLine) = "[" & LCase(section) & "]"
Line Input #nr, curLine
Loop

' read until end of file or key is found
Do Until EOF(nr)
Line Input #nr, curLine
' key found?
If LCase(curLine) Like LCase(key) & "=*" Then
' yes -> outta here
getIniString = Mid(curLine, Len(key) + 2)
Exit Do
End If
Loop
Close nr
End Function


Cheers,
Martin
 
W

Word Heretic

G'day "D" <[email protected]>,

Its a built in limitation of most string functions from VBA. When you
call a C etc function you can pass it the pointers to your string
variable and it will come back longer than what VBA uses because it is
based on the old WordBasic rather than being a true 16 bit
implementation.

Because of this, the strings RLE is capable of a 16bit store, just the
VBA functions only use the lower 8 bits of the store and no more.

So what we normally do is chop off the first 255 and deal with it,
then keep adding 255 char buffers whilst the len>255, then add the
last bit once we are down to a LWM again.

So, when you go to pass your massive string to the VBA
PrivateProfileString function, it will only read the first 8bits (255)
chars of the string. If you could be stuffed looking up the spec in
the Binary File Format, you may find the store is a 16 for private
profiles (Long) thus opening the potential for using deeper functions
to access the space.

It is far easier to chop and go :)


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


D reckoned:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top