Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from INI file

Status
Not open for further replies.

moshemc

IS-IT--Management
Jan 24, 2009
5
IL
Hi all,

I'm using the "sgetini" function for years. It's a well-known function that reads INI files very well:

Code:
Public Function sGetINI(sINIFile As String, sSection As String, sKey _
                As String, sDefault As String) As String
    Dim sTemp As String * 256
    Dim nLength As Integer
    sTemp = Space$(256)
    nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, _
              255, sINIFile)
    sGetINI = Left$(sTemp, nLength)
End Function

It works very well with strings up to 256 characters.
Now I have a situation in which I have more than 256 chars. I try to change the numbers in the function accordingly, but nothing helps.
Do you know for a solution?
Do you have any alternate functions that works well?

Thanks in advance


 
How about something like this:
Code:
Public Function sGetINI(sINIFile As String, sSection As String, sKey _
                As String, sDefault As String) As String
    Dim sTemp As String * 2048
    Dim nLength As Long
    Dim nBuffer As Long
    sTemp = Space$(2048)
    nBufferSize = Len(sTemp)
    
    nLength = GetPrivateProfileString(sSection, sKey, sDefault, sTemp, _
              nBuffer, sINIFile)
    sGetINI = Left$(sTemp, nLength)
End Function
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top