07. september 1999 - 21:52
Der er
1 kommentar og
1 løsning
Skrive og læse i en .ini fil
Jeg vil lave et program der skal skrive nogle ting ind i en .ini fil ex:
Fil: Xion.ini
[Job1]
Command=xxx
Date=xx
Time=xx
[Job2]
Command=xxx
Date=xx
Time=xx
Hvordan for jeg dette skrevet i min INI og hvordan læser jeg det igen ?
Når jeg skal læse INI filen kender jeg [Section] og Key= men hvad er koden ?? (VB5)
Et eksempel vil være det bedste svar
07. september 1999 - 22:12
#1
Siden du er i VB5 kan bruge API funktionerne GetPrivateProfileString, ReadPrivateProfileString til at gøre dette. Søg på disse og du vil finde en hel del eksempler...
Slettet bruger
08. september 1999 - 08:24
#2
Lav en modul der indeholder følgende, og brug derefter GetString og WriteString :
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
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
Function Getstring(strSection As String, strEntry As String, strStdStreng As String, bytValueSpace As Byte, Optional strinifil As String = "") As String
'Get a string from ini-file
Dim strTemp As String ' Temporary String
Dim lngBytesHentet As Long ' How many bytes was recieved by the API call
Dim strEntryValue As String
strTemp = Space(bytValueSpace)
lngBytesHentet = GetPrivateProfileString(strSection, strEntry, strStdStreng, strTemp, Len(strTemp), strinifil)
strEntryValue = Left(strTemp, lngBytesHentet)
Getstring = IIf(strEntryValue = "", strStdStreng, strEntryValue)
End Function
Sub WriteString(strSection As String, strEntry As String, strValue As String, Optional strinifil As String = "")
'Write a string to ini-file
WritePrivateProfileString strSection, strEntry, strValue, strinifil
End Sub