Results 1 to 2 of 2

Thread: text file specific line

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374

    Post

    Can somebody show me the syntaxt on how to read just one line of a text file and how to specify which line to read?

    e.g. if I have a .ini file like

    [PROGRAM NAME]
    ODBC
    Total_Fields = 6

    what syntax should I use to return just the line Total_Fields = 6?

    Thanks in advance

    Andrew


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

    Post

    If you're using an INI File Format you'd be better off using the GetPrivateProfileString API which is specificly for retrieving data from an INI File, eg.
    Code:
    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 Command1_Click()
        Dim sBuff As String * 255
        Call GetPrivateProfileString("PROGRAM NAME", "Total_Fields", "", ByVal sBuff, 255, "C:\MyINI.ini")
        If Left(sBuff, 1) <> Chr(0) Then MsgBox Left(sBuff, InStr(sBuff, Chr(0)) - 1)
    End Sub
    Where MyINI.ini is the Name of your INI File.

    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

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