For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > January 2006 > Problem reading from ini file









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem reading from ini file
Vlad

2006-01-27, 6:56 pm

Hi All,

I have been using the function below to read data from ini files - I
think I found it on msdn somewhere.

It seems to have problems when the section of the ini file contains
blank spaces in string:-

i.e.

The_dog, The_cat, The_mouse - would work fine but

The_Dog, The cat, The_mouse - would just return The_Dog, The

Can anyone either help me with why or suggest a more robust way of
tackling this.

Here's my existing function:-

TIA

Function copy_of_ReadFromFile(strFileSection As String, strKey As
String, strMySystemFile As String) As String
'parameters: strFileSection - string used as a file subheader for every
section
' strKey - string used as key to read the value from file (
ex: UserName)
'returns: a string with the value tied to the key when written to
file
' a null string "" if Key is not on file

Dim strValue As String
Dim lngRetLen As Long

strValue = String(READ_BUFF + 1, Space(1))
lngRetLen = GetPrivateProfileStringByKeyName(strFile
Section,
strKey, "", strValue, READ_BUFF, strMySystemFile)
If lngRetLen > 1 Then
ReadFromFile = Left(strValue, lngRetLen)
Else
ReadFromFile = ""
End If
End Function

Vlad

2006-01-27, 6:56 pm

Apologies - I have now worked it out.

It was to do with the size of READ_BUFF as I had it set to 255 and
there were 279 characters in the section I was trying to extract.

Karl E. Peterson

2006-01-27, 6:56 pm

Vlad wrote:
> Hi All,
>
> I have been using the function below to read data from ini files - I
> think I found it on msdn somewhere.
>
> It seems to have problems when the section of the ini file contains
> blank spaces in string:-


Can't say what's wrong there, but it doesn't look very clean. For an easy
to use, drop-in ready module, see http://vb.mvps.org/samples/kpini
--
Working without a .NET?
http://classicvb.org/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com