updating visual 6.0 code to .net

VbStudent302

Member
Joined
Oct 27, 2004
Messages
7
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 doesnt 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.
 
How have you defined GetPrivateProfileString in your code?

Try the following code and see if it works
Code:
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
 
Last edited by a moderator:
Thank you very much, the code excuted perfectly now when i used ur code + adding System.text. in front of StringBuilder. THANKS :)
 
Back
Top