Results 1 to 3 of 3

Thread: ini files

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2001
    Location
    Auckland, New Zealand
    Posts
    21

    Talking

    Hi, anyone know how to use ini files?

    I'm writing an app that uses the write function to write lines of data to a text file and need an ini file so different versions can have different field names (and a different number of fields for that matter) in the tables.

    I assume I write a text file settings.ini with lines like:
    field1name = TIME_STAMP
    then open it using:
    open C:\settings.ini for input as #1.

    How do I glean out the info I need then and put in to lines of code?

    Also, if I have say fieldname1 to fieldname200, how do I deal with the empty ones for tables with less than 200 fields? In particular in a write line like this:
    Write #1, rstMon("TIME_STAMP") & "", rstMon("RANGE_ERR") & ""...

    Thanks!!!

  2. #2
    Jethro
    Guest

    Thumbs up Have just had this answered

    There's a tutorial on this site about this exact thing. Cannot locate it at the moment, but it should not be too hard to find.

  3. #3
    Addicted Member Shrog's Avatar
    Join Date
    Aug 1999
    Location
    Darkest Africa
    Posts
    186
    Here are some of the INI file basics. There is a lot more documentation on the internet about this stuff - just do a search on some of these API definitions. The coding below is a good place to start though.
    Code:
    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
    Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" _
                    (ByVal lpAppName As String, ByVal lpString As String, _
                     ByVal lpFileName As String) As Long
    Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" _
                    (ByVal lpApplicationName As String, ByVal lpKeyName As String, _
                     ByVal nDefault As Long, ByVal lpFileName As String) As Long
    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 GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" _
                    (ByVal lpAppName As String, ByVal lpReturnedString As String, _
                     ByVal nSize As Long, ByVal lpFileName As String) As Long
    
    
    Public Function SaveItem(ByRef vSection As String, ByRef vKey As String, _
                             ByRef vValue As String, ByRef vFileName As String) As Long
        'writes one item of data to the file.
        SaveItem = WritePrivateProfileString(vSection, vKey, vValue, vFileName)
    End Function
    Public Function GetItem(ByRef vSection As String, ByRef vKey As String, _
                            ByRef vDefault As String, ByRef vFileName As String) As String
        'reads one item of data from the file.
        Dim lReturnedString As String * 256
        Dim lSize As Long
        Dim lResult As Long
        
        lSize = Len(lReturnedString) + 1
        
        lResult = GetPrivateProfileString(vSection, vKey, vDefault, lReturnedString, lSize, vFileName)
        
        GetItem = Left$(lReturnedString, lResult)
        
    End Function
    
    Public Function GetItemNames(ByRef vSection As String, ByRef vFileName As String) As String
        'reads all the keys in a section.
        Dim lReturnedString As String
        Dim lSize As Long
        Dim lResult As Long
        lReturnedString = String$(1048576, Chr$(0))
        lSize = Len(lReturnedString) + 1
        
        lResult = GetPrivateProfileSection(vSection, lReturnedString, lSize, vFileName)
        
        If lResult = 0 Then
            'Do error processing
        Else
            GetItemNames = Left$(lReturnedString, lResult)
        End If
        
    End Function
    Hope this helps.
    Shrog
    VB6 Ent SP5
    Win2000

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