VbStudent302 Posted November 19, 2005 Posted November 19, 2005 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. Quote
VbStudent302 Posted November 19, 2005 Author Posted November 19, 2005 oh that leftS in the code is a Left$ Quote
VbStudent302 Posted November 19, 2005 Author Posted November 19, 2005 lol and that Stringbuffer = pad left stuff is really "StringBuffer = Space(2000)" Quote
Administrators PlausiblyDamp Posted November 19, 2005 Administrators Posted November 19, 2005 (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 November 19, 2005 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VbStudent302 Posted November 20, 2005 Author Posted November 20, 2005 Thank you very much, the code excuted perfectly now when i used ur code + adding System.text. in front of StringBuilder. THANKS :) Quote
Recommended Posts