用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - vb代码库

用VB.NET实现对.INI文件的读写操作的类

2020-10-26 作者: 红魔举报

[vb]代码库

Option Explicit On

Module INI
    'INICont.bas Ver 1.0+a  INI    '====================================================================
    'GetIntFromINI( sectionName , keyName , defaultValue, iniPath )
    '
    '          sectionName:节点名

    '          keyName    :配置项名
    '          defaultValue:默认值

    '          iniPath       :INI配置文件的路径

    '
    '====================================================================

      //声明从INI配置文件中获取类型为Int的配置项的值的系统函数
      Private Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Integer, ByVal lpFileName As String) As Integer

     //声明从INI配置文件中获取类型为string的配置项的值的系统函数
    Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

      //声明向INI配置文件中写入类型为string的配置项的值的系统函数

      Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer

     //从INI配置文件中获取类型为Int的配置项的值

    Public Function GetIntFromINI(ByVal sectionName As String, ByVal keyName As String, ByVal defaultValue As Integer, ByVal iniPath As String) As Integer

               GetIntFromINI = GetPrivateProfileInt(sectionName, keyName, defaultValue, iniPath)
    End Function

     //从INI配置文件中获取类型为string的配置项的值
    Public Function GetStrFromINI(ByVal sectionName As String, ByVal keyName As String, ByVal defaultValue As String, ByVal iniPath As String) As String
        Dim buffer As String 

        Dim rc As Integer 

        buffer = Space(256)
       

        rc = GetPrivateProfileString(sectionName, keyName, defaultValue, buffer, buffer.Length, iniPath)
        

        GetStrFromINI = Left(buffer, InStr(buffer, vbNullChar) - 1)
    End Function

     //向INI配置文件中写入类型为string的配置项的值

     Public Function WriteStrINI(ByVal sectionName As String, ByVal keyName As String, ByVal setValue As String, ByVal iniPath As String) As Integer
        Dim rc As Integer 

        rc = WritePrivateProfileString(sectionName, keyName, setValue, iniPath)

        If rc Then
            rc = 1
        End If
        WriteStrINI = rc
    End Function

  End Module


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...