ini文件是windows的系统配置文件, 被用来对操作系统或特定程序初始化或进行参数设置. 在Windows系统中,INI文件是很多,最重要的就是“System.ini”、“System32.ini”和“Win.ini”。该文件主要存放用户所做的选择以及系统的各种参数。用户可以通过修改INI文件,来改变应用程序和系统的很多配置。

中间的数据格式一般为:

;注释(Comments)

[Section1 Name]
KeyName1=value1
KeyName2=value2
...

[Section2 Name]
KeyName1=value1
KeyName2=value2

ini 文件可以分为几个 Section,每个 Section 的名称用 [] 括起来,在一个 Section 中,可以有很多的 Key,每一个 Key 可以有一个值并占用一行,格式是 Key=value,注释以分号";"开头。

Windows提供了几个有用的API来读写操作INI文件:

  GetPrivateProfileString - 从 ini 文件的某个 Section 取得一个 key 的字符串
  GetPrivateProfileSection - 从 ini 文件中读出整个 Section 的内容
  WritePrivateProfileSection - 将一个整个 Section 的内容入 ini 文件的指定 Section 中
  WritePrivateProfileString - 将一个 Key 值写入 ini 文件的指定 Section 中


'declarations for working with Ini files
Private Declare Function GetPrivateProfileSection()Function GetPrivateProfileSection Lib "kernel32" Alias _
"GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long

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

Private Declare Function WritePrivateProfileString()Function WritePrivateProfileString Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, _
ByVal lpString As Any, ByVal lpFileName As String) As Long



'reads an Ini string
Public Function ReadIni()Function ReadIni(Filename As String, Section As String, Key As String) As String
    Dim RetVal As String * 255
    
    Dim v As Long
    v = GetPrivateProfileString(Section, Key, "NotFound", RetVal, 255, Filename)
    
    ReadIni = Left(RetVal, v)
End Function

'reads an Ini sectionPublic
Function ReadIniSection()Function ReadIniSection(Filename As String, Section As String) As String
    Dim RetVal As String * 255
    
    Dim v As Long
    v = GetPrivateProfileSection(Section, RetVal, 255, Filename)
    
    ReadIniSection = Left(RetVal, v )
End Function

'writes an Ini string
Public Sub WriteIni()Sub WriteIni(Filename As String, Section As String, Key As String, Value As String)
    WritePrivateProfileString Section, Key, Value, Filename
End Sub

'writes an Ini section
Public Sub WriteIniSection()Sub WriteIniSection(Filename As String, Section As String, Value As String)
    WritePrivateProfileSection Section, Value, Filename
End Sub

转载于:https://www.cnblogs.com/iswszheng/archive/2009/04/24/1442737.html

Visual basic 6读写ini文件相关推荐

  1. VC中读写ini文件

    我们写的程序当中,总有一些配置信息需要保存下来,以便完成程序的功能,最简单的办法就是将这些信息写入INI文件中,程序初始化时再读入.具体应用如下: 一.将信息写入.INI文件中. 1.所用的WINAP ...

  2. vbs脚本读写INI文件

    vbs脚本读写INI文件 转载于:https://www.cnblogs.com/bull_think/archive/2012/08/21/2649838.html

  3. C#学习笔记——读写ini文件

    1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: ...

  4. C#关于读写INI文件

    C#关于读写INI文件 什么是ini文件就是一个配置文件,一般把数据库等配置信息放进去,然而,改变数据库的密码,数据库名称,ip等,不要改源码重新编译,只需要用记事本打开set.ini 文件,修改保存 ...

  5. C# 读写Ini文件

    ini文件在Win95以前比较盛行,之后由于出册表等技术的出现,ini技术主键退居二线,不过对于一些小项目,读写ini文件还是很适用的. Windows API提供了读写配置文件的操作,在C#程序中只 ...

  6. 在 WinCe 平台读写 ini 文件

    在上篇文章开发 windows mobile 上的今日插件时,我发现 wince 平台上不支持例如 GetPrivateProfileString 等相关 API 函数.在网络上我并没有找到令我满意的 ...

  7. 十、封装python3读写ini文件类

    自己编写封装的python3读写ini文件类. main.py # -*- coding: utf-8 -*- import os import configparserclass OperateIn ...

  8. 在.NET中读写INI文件 ——兼谈正则表达式的应用

    INI文件是Windows平台上的一种较常用的软件配置文件格式,Windows应用程序常常使用它来保存一些配置信息.它一般是由数个包含key-value对的Section组成,每个key-value对 ...

  9. 转:c++builder读写INI文件

    转:c++builder读写INI文件 //包含文件 #include <inifiles.hpp> //写文件 TIniFile *ini; ini=new TIniFile(Chang ...

最新文章

  1. python装饰器类-Python类装饰器
  2. HTTPD(三)--HTTP2.4.9编译安装
  3. 文巾解题 面试题 01.02. 判定是否互为字符重排
  4. Python 科学计算库 Numpy(一)—— 概述
  5. 初中计算机word教案ppt,初中信息技术课件 用Word处理文字.ppt
  6. 车已经买有近一个月了,技术也在提升中
  7. ajax处理返回的xml数据,使用AJAX调用WebService返回xml不返回json原因以及解决办法...
  8. android平台的s5pc110触摸屏驱动分析
  9. MacBook常用快捷键有哪些?
  10. pgAdmin III 导出excel数据
  11. FPN网络详解(知识点记录)
  12. 这里是一个简单的CRM客户关系管理系统的开发教程,你值得拥有哟!
  13. mooc作业怎么上传附件_社会组织年报附件上传常见问题解决方案
  14. php5.6安装php-gd,centos73下php5.6安装GD库
  15. EUI学习之自定义皮肤
  16. swiper的小bug slideTo方法不触发slideChangeTransitionStart(swiper)
  17. java——API——ArrayList集合
  18. 会员服务-获取所有会员等级
  19. Java回炉之语言基础
  20. 几类自适应波束形成算法推导

热门文章

  1. IOS开发之coreData
  2. Python学习之urlib模块和urllib2模块学习
  3. AirPrint: 无交互的后台打印实现(Print without UI,iOS8+)
  4. HTML 静态网页制作12月2日表单样式
  5. WinAPI: Ellipse - 绘制椭圆
  6. Windows 7里的计算器,中文版,给Vista和2008用吧
  7. [电子商务网站设计] 之 My Space
  8. kafka关闭终端继续执行命令(转载)
  9. Python in worker has different version 3.7 than that in driver 3.6
  10. BootStrap轮播图失效