VB6 中处理 INI 文件的方法

Attribute VB_Name = "modINIFile"
Option Explicit


Public 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

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 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 Declare Function WritePrivateProfileSection Lib "kernel32" _
        Alias "WritePrivateProfileSectionA" _
        (ByVal lpAppName As String, _
        ByVal lpString As String, _
        ByVal lpFileName As String) As Long


' 从INI 文件中取得相关项
' 02 Mar 2006 James      Space(128)=> Space(500)
Public Function GetItemFromINI(Section As String, _
            Key As String, FileName As String) As String

    Dim Valid As String
    Dim Size As Integer
    Dim Path As String
    Dim s As String

    s = Space(500)
    Size = Len(s)
    Valid = GetPrivateProfileString(Section, Key, "", s, Size, FileName)
    s = Left(s, Valid)
    GetItemFromINI = Trim(s)


End Function


' 将新的INI Item 的值,写入INI文件项中
Public Sub writeItemToINI(Section As String, _
            Key As String, Value As String, FileName As String)
   
    WritePrivateProfileString Section, Key, Value, FileName
   
End Sub

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值