hi,
hi how i can make ini file to my program to save the options in it.
Printable View
hi,
hi how i can make ini file to my program to save the options in it.
You need to use API calls.
Code: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 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
as RobDog said... then you can use them like this
VB Code:
Option Explicit Private Declare Function GetPrivateProfileString _ Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal _ lpApplicationName As String, ByVal lpKeyName As String, _ ByVal lpDefault As String, ByVal lpReturnedString As _ String, ByVal nSize As Long, 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 Private Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String Dim strbuffer As String Let strbuffer$ = String$(750, Chr$(0&)) Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$)) End Function Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String) Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$) End Sub Private Sub Command1_Click() 'creates Test.ini that look like this: '[DBParam] 'DBNAME=C:\myapp\db\mydb.mdb '[Temp] 'TMPPATH=C:\myapp\tmp WriteINI "DBParam", "DBName", "C:\myapp\db\mydb.mdb", "C:\TEST.INI" WriteINI "Temp", "TMPPath", "C:\myapp\tmp", "C:\TEST.INI" End Sub Private Sub Command2_Click() 'reading the settings saved above :-) MsgBox ReadINI("DBParam", "DBName", "C:\TEST.INI") MsgBox ReadINI("Temp", "TMPPath", "C:\TEST.INI") End Sub Private Sub Command3_Click() 'Deletes the DBNAME key entierly 'so that the ini looks like this: '[DBParam] '[Temp] 'TMPPATH=C:\myapp\tmp WriteINI "DBParam", "DBName", vbNullString, "C:\TEST.INI" End Sub