Weiss jemand ob und wie ich mit den Befehlen „GetSetting“ und „SaveSetting“ auch selbst angelegte .ini-Dateien bearbeiten kann.
Hallo Michael,
soweit ich weiss kannst Du mit diesen beiden Funktionen nur Werte in die Registry ablegen/lesen. Wenn Du INI-Dateien bearbeiten willst brauchst Du die API-Funktionen GetPrivateProfileString und WritePrivateProfileString.
Weitere Informationen hierzu findest Du unter: http://www.vbapi.com/.
Gruß Thomas
INI Dateien liest man am einfachsten über
API Funktionen. Für Interressierte hier
ein Beispiel Modul, welches diese Problematik
kapselt:
Option Explicit
Const INI\_FILE = "TEST.INI"
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" \_
(ByVal lpApplicationName As String, ByVal lpKeyName As Any, \_
ByVal lpDefault As String, ByVal lpReturnedString As String, \_
ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" \_
(ByVal lpApplicationName As String, ByVal lpKeyName As String, \_
ByVal nDefault As Long, ByVal lpFileName As String) As Long
Public 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
Public Function GetINIString(ByVal sSection As String, \_
ByVal sKey As String, Optional sDefault As String) As String
Dim ReturnString As String
Dim ReturnValue As Long
On Error GoTo hErr:
ReturnString = String$(255, 0)
ReturnValue = GetPrivateProfileString(sSection, sKey, \_
sDefault, ReturnString, Len(ReturnString), App.Path & "\" & INI\_FILE)
If Left(ReturnString, InStr(ReturnString, Chr$(0)) - 1) = sDefault Then
GetINIString = sDefault
Else
GetINIString = Left(ReturnString, InStr(ReturnString, Chr$(0)) - 1)
End If
Exit Function
hErr:
End Function
Public Function GetININumber(ByVal sSection As String, \_
ByVal sKey As String, Optional nDefault As Long) As Long
On Error GoTo hErr:
GetININumber = GetPrivateProfileInt(sSection, sKey, nDefault, App.Path & "\" & INI\_FILE)
hErr:
End Function
Public Sub WriteINIString(ByVal sSection As String, \_
ByVal sKey As String, ByVal sValue As String)
Dim nRet As Long
If Len(sSection) \> 0 Then
nRet = WritePrivateProfileString(sSection, sKey, sValue, App.Path & "\" & INI\_FILE)
End If
End Sub