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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading INI files 1

Status
Not open for further replies.

marcseys

Programmer
Dec 6, 1999
23
0
0
GB
I was using in VB6 a function "readfromini" which was using an api-call to GetPrivateProfileString.

After migration to VB.NET this function is not working any longer. Have already consulted the MSDN, but the solution there are neither making the function working.

Is there someone who had the same issue and found a solution?

Regards
Marc
 
API Calls are still needed. Add this code to a class of your own

Code:
    'INI setting Win32 APIs
    Private Declare Function WritePrivateProfileString Lib "kernel32" _
        Alias "WritePrivateProfileStringA" _
        (ByVal SectionName As String, _
        ByVal KeyName As String, _
        ByVal KeyValue As String, _
        ByVal FileName As String) As Integer

    Private Declare Function GetPrivateProfileString Lib "kernel32" _
        Alias "GetPrivateProfileStringA" _
        (ByVal SectionName As String, _
        ByVal KeyName As String, _
        ByVal [Default] As String, _
        ByVal ReturnedString As String, _
        ByVal StringSize As Integer, _
        ByVal FileName As String) As Integer

    '//INI FILE
    Private Shared sINIFileName As String = InstallDir + "mis.ini"

    Public Shared Function INIRead(ByVal sSection As String, ByVal sKeyName As String, ByVal oDefaultValue As Object) As Object

        Dim iRet As Integer
        Dim sBuf As String = Space(128)

        Try
            iRet = GetPrivateProfileString(sSection, sKeyName, CStr(oDefaultValue), sBuf, sBuf.Length, sINIFileName)
            Return sBuf.Substring(0, iRet)

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Function

    Public Shared Sub INIWrite(ByVal sSection As String, ByVal sKeyName As String, ByVal oSetting As Object)

        Try
            WritePrivateProfileString(sSection, sKeyName, CStr(oSetting), sINIFileName)

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

    End Sub



Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top