Hejsan, Nedanstående är för att läsa och skriva till inifiler.INI-fil och listview!
Jag har en INI-fil som ser ut såhär:
[Server1]
hostname=asda
maxplayers=123
password=asd
map=asdas
levelrotation=12
winlimit=12
roundlimit=4
freezetime=3
buytime=3
startmoney=16000
[Server2]
hostname=asda
maxplayers=123
password=asd
map=asdas
levelrotation=12
winlimit=12
roundlimit=4
freezetime=3
buytime=3
startmoney=16000
Hur gör jag om jag vill ladda in detta i en Listview vid start?
Ska tillägga också att det är bara hostname, password, maxplayers och map som skall laddas i listviewn. Men de andra ska finnas i variabler som kan användas på andra sätt.Sv: INI-fil och listview!
Hur du får in datan i listviewen får du lista ut själv :-)
<code>
'declares for ini controlling
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private 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
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
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
'reads ini string
Public Function Read(ByVal ConfigObject As String, ByVal Section As String, ByVal Key As String, Optional ByVal strDefault As String) As String
Dim RetVal As String * 255, v As Long
v = GetPrivateProfileString(Section, Key, strDefault, RetVal, 255, ConfigObject)
Read = Left(RetVal, v)
End Function
'reads ini section
Public Function ReadSection(ByVal ConfigObject As String, ByVal Section As String) As String
Dim RetVal As String * 4096, v As Long
v = GetPrivateProfileSection(Section, RetVal, 4096, ConfigObject)
ReadSection = Left(RetVal, v - 1)
End Function
'writes ini
Public Sub Save(ByVal ConfigObject As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
WritePrivateProfileString Section, Key, Value, ConfigObject
End Sub
'writes ini section
Public Sub SaveSection(ConfigObject As String, Section As String, Value As String)
WritePrivateProfileSection Section, Value, ConfigObject
End Sub
'removes ini section
Public Sub RemoveSection(ConfigObject As String, Section As String)
WritePrivateProfileString Section, vbNullString, "", ConfigObject
End Sub
</code>