Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have been trying to get this function that reads from .ini files in VB 6.0 to work in VB .net.

 

Public Function ReadINI(ByVal INISection As String, ByVal INIKey As String, ByVal INIFile As String) As String

Dim StringBuffer As String

Dim StringBufferSize As Long

StringBuffer = ""

StringBuffer = StringBuffer.PadLeft(2000)

StringBufferSize = Len(StringBuffer)

StringBufferSize = GetPrivateProfileString(INISection, INIKey, "", StringBuffer, StringBufferSize, INIFile)

If StringBufferSize > 0 Then

ReadINI = LeftS(StringBuffer, StringBufferSize)

Else

ReadINI = ""

End If

End Function

 

I have got the writeIni function to work and i tried to change the "Left$(" to "microsoft.visualbasic.Left" but to no avail the code doesn't seem to work.

 

Any help would be greatly aprreciated. and im sorry if this is in the wrong thread i didnt know where to put it.

  • Administrators
Posted (edited)

How have you defined GetPrivateProfileString in your code?

 

Try the following code and see if it works

Private Declare Auto Function GetPrivateProfileString Lib "kernel32" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, _
           ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer


Public Function ReadINI(ByVal INISection As String, ByVal INIKey As String, ByVal INIFile As String) As String


Dim StringBuffer As New StringBuilder(2000)
Dim StringBufferSize As Integer

StringBufferSize = StringBuffer.Capacity
StringBufferSize = GetPrivateProfileString(INISection, INIKey, "", StringBuffer, StringBufferSize, INIFile)

Return StringBuffer.ToString()

End Function

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...