ADICIONAR TEXTOS DE CHAVES DE INI PARA LISTBOX

CASPEREARK 11/12/2003 00:53:55
#647
Olá pessoal!

Estou precisando que alguem me ensine como se faz para colocar o texto de chaves de arquivo INI (ex: file01=) num listbox independentemene do numero de chaves que existir no INI.

Grato!
USUARIO.EXCLUIDOS 11/12/2003 05:42:33
#659
Resposta escolhida
Faz isso no módulo.

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Function WriteINI(sSection As String, _
sKey As String, ByVal sValue As String) As Boolean

Dim lR As Long
Dim sItemValue As String

sValue = Trim$(sValue)
sItemValue = Trim$(sItemValue) & vbNullChar
lR = WritePrivateProfileString(sSection, sKey, _
sValue, InAppPath(App.Title & ".ini"))

If lR = 0 Then
WriteINI = False
Else
WriteINI = True
End If
End Function

Public Function ReadINI(sSection As String, _
sKey As String, sDefault As String) As String

Dim lR As Long
Dim sReturnedValue As String

sReturnedValue = Space$(512)
lR = GetPrivateProfileString(sSection, sKey, sDefault, _
sReturnedValue, 512, InAppPath(App.Title & ".ini"))
If lR = 0 Then
ReadINI = vbNullString
Else
ReadINI = Left$(sReturnedValue, lR)
End If
End Function

Public Function AppPath() As String
If Right$(App.Path, 1) = "\" Then
AppPath = App.Path
Else
AppPath = App.Path & "\"
End If
End Function

Public Function InAppPath(Name As String) As String
'if AppPath
If Right$(App.Path, 1) = "\" Then
InAppPath = App.Path & Name
Else
InAppPath = App.Path & "\" & Name
End If
End Function


E toda a vez que você for escrever no arquivo use a função WriteINI() e toda fez que for ler use a função ReadINI().

Alguma dúvida é só postar no fórum que te ajudo.
Tópico encerrado , respostas não são mais permitidas