日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Visual basic 6读写ini文件

發布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Visual basic 6读写ini文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。