Results 1 to 2 of 2

Thread: how to read from an INI file???

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I would like to type a caption into a text box and then save that caption into an INI file sao that the next time I staret the program the caption is in the form.caption. I use this code to write to the file:

    open "C:\Caption.ini" for output as #1
    write #1, text1.text
    close # 1

    now, thats the writing side of things taken care of but how do I read the caption from the file and place it in form1s caption???

    Richard

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    If you want to use a True INI File, then you need to use the GetPrivateProfileString and WritePrivateProfileString API's, eg.
    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
    
    Private Sub Form_Load()
        Dim sBuff As String * 255
        'Load the Caption from the INI File.
        Call GetPrivateProfileString(App.Title, "Caption", "Default Caption", sBuff, 255, "C:\Caption.ini")
        Caption = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
        Text1 = Caption
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Save the New Caption to the INI File.
        Call WritePrivateProfileString(App.Title, "Caption", ByVal Text1.Text, "C:\Caption.ini")
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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