FUN?ÃO PARA LER INI

SNNIFFER 04/05/2017 12:17:57
#473727
Opa,

Num modulo para ler arquivo ini uso:
  Imports System.Text
Imports System.Runtime.InteropServices

Module INI
<DllImport([Ô]kernel32.dll[Ô], SetLastError:=True)> Public Function WritePrivateProfileString _
(ByVal lpApplicationName As String,
ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
End Function

<DllImport([Ô]kernel32.dll[Ô], SetLastError:=True)> Public Function GetPrivateProfileString(
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
End Function

Public Function DataLoad(ByVal strItem As String) As String
Dim strValue As StringBuilder = New StringBuilder(255)
Dim intSize As Integer

intSize = GetPrivateProfileString([Ô][content][Ô], strItem, [Ô][Ô], strValue, 255, [Ô]settings.ini[Ô])

Return strValue.ToString
End Function


Para usa-la:



  msgbox (DataLoad([Ô]sidebar[Ô])) 


mas, não está retornando nada.

O arquivo ini exemplo:

  [content]
sidebar=teste
over_line=blue

DS2T 04/05/2017 12:28:24
#473729
Resposta escolhida
Possivelmente por causa dessa chamada:

        intSize = GetPrivateProfileString([Ô][content][Ô], strItem, [Ô][Ô], strValue, 255, [Ô]settings.ini[Ô])


Tente retirar os colchetes, assim:

        intSize = GetPrivateProfileString([Ô]content[Ô], strItem, [Ô][Ô], strValue, 255, [Ô]settings.ini[Ô])
Tópico encerrado , respostas não são mais permitidas