I need to save the settings a user defines in my application and they need to be restored the next time the app is run.. saving setting in a ini file
Printable View
I need to save the settings a user defines in my application and they need to be restored the next time the app is run.. saving setting in a ini file
Download my sample project from HERE.
UMMM I dont under stand that code
Please Explain
I'll try...
Put this code in a module
VB Code:
Option Explicit 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 WriteIniFile(ByVal sIniFileName As String, ByVal sSection As String, ByVal sItem As String, ByVal sText As String) As Boolean Dim i As Integer On Error GoTo sWriteIniFileError i = WritePrivateProfileString(sSection, sItem, sText, sIniFileName) WriteIniFile = True Exit Function sWriteIniFileError: WriteIniFile = False End Function Function ReadIniFile(ByVal sIniFileName As String, ByVal sSection As String, ByVal sItem As String, ByVal sDefault As String) As String Dim iRetAmount As Integer 'the amount of characters returned Dim sTemp As String sTemp = String$(200, 0) 'fill with nulls iRetAmount = GetPrivateProfileString(sSection, sItem, sDefault, sTemp, 200, sIniFileName) sTemp = Left$(sTemp, iRetAmount) ReadIniFile = sTemp End Function
then when you want to write somthing to a ini file it goes like this, this will write the current time, you can put this in a button or form exit
VB Code:
WriteIniFile App.Path & "\settings.ini", "Category Name", "Title", Time
Then to call it out you can do this, this will call it out and put it into the textbox
VB Code:
Text1.Text = ReadIniFile(App.Path & "\settings.ini", "Category Name", "Title", "")
that will put the time that is written to your ini file back into text1. I would put this part in form load