Results 1 to 5 of 5

Thread: Help with module for INI files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258

    Post

    I have an ini file that I need to read and write to
    It looks like this

    [Friends]
    Jonnie:34.131.256.204
    Bill:262.159.45.224


    Does anyone have a routine or a bas module that will let me get the entries under [FRIENDS] and get the total count
    of the entries under the heading ?


    Thanx guys
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  2. #2
    Guest
    Here you go:

    Code:
    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    
    Public Function readini(strsection As String, strkey As String, strfullpath As String) As String
       Dim strbuffer As String
       Let strbuffer$ = String$(750, Chr$(0&))
       Let readini$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
    End Function
    
    
    Usage:
    
    Text1.text = readini("Friends", "Jonnie", "C:\Friends.ini")

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Thanx =)
    How bout this now

    what happens If I Dont know the entries under [Friends]
    How can I Find out how many entries there are ?
    Also how bout a writeini function ?
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  4. #4
    Guest
    Here is how to Write an INI:

    Code:
    Public 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
    
    Public Sub writeini(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
        Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
    End Sub
    
    Call writeini("Friends.ini", "NewFriend", "Number", "C:\Friends.ini")
    Don't know how to find all entries under [Friends], but you can open and through VB and look through it.

    Code:
    Open "C:\Friends.ini" For Input As #1 
    Text1.Text = Input$(LOF(1), 1) 
    Close #1

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Thanx again Mathew , I appreciate your help
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

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