Results 1 to 4 of 4

Thread: saving setting in a ini file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    saving setting in a ini file

    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

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    389

    Re: saving setting in a ini file

    UMMM I dont under stand that code

    Please Explain

  4. #4
    Addicted Member
    Join Date
    Dec 2005
    Posts
    163

    Re: saving setting in a ini file

    I'll try...

    Put this code in a module

    VB Code:
    1. Option Explicit
    2.  
    3. Declare Function GetPrivateProfileString Lib "kernel32" Alias _
    4.       "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
    5.       lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As _
    6.       String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    7.  
    8. Declare Function WritePrivateProfileString Lib "kernel32" Alias _
    9.       "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _
    10.       lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    11.  
    12.  
    13. Function WriteIniFile(ByVal sIniFileName As String, ByVal sSection As String, ByVal sItem As String, ByVal sText As String) As Boolean
    14.    Dim i As Integer
    15.    On Error GoTo sWriteIniFileError
    16.  
    17.    i = WritePrivateProfileString(sSection, sItem, sText, sIniFileName)
    18.    WriteIniFile = True
    19.  
    20.    Exit Function
    21. sWriteIniFileError:
    22.    WriteIniFile = False
    23. End Function
    24.  
    25.  
    26. Function ReadIniFile(ByVal sIniFileName As String, ByVal sSection As String, ByVal sItem As String, ByVal sDefault As String) As String
    27.    Dim iRetAmount As Integer   'the amount of characters returned
    28.    Dim sTemp As String
    29.  
    30.    sTemp = String$(200, 0)   'fill with nulls
    31.    iRetAmount = GetPrivateProfileString(sSection, sItem, sDefault, sTemp, 200, sIniFileName)
    32.    sTemp = Left$(sTemp, iRetAmount)
    33.    ReadIniFile = sTemp
    34. 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:
    1. 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:
    1. 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
    If this post has helped you please rate it by clicking the scales to the left of this post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width