VB讀取ini檔案的函式

2021-04-12 18:00:04 字數 1974 閱讀 5501

option explicit

public errormsg as string

private sub class_initialize()

errormsg = vbnullstring

end sub

'寫入----------------------------------

public function writestring(inifilename as string, section as string, key as string, value as string) as boolean

writestring = false

errormsg = vbnullstring

if inifilename = "" then

errormsg = "ini file has not been specifyed!"

exit function

end if

if writeprivateprofilestring(section, key, value, inifilename) = 0 then

errormsg = "failed to write to the ini file!"

exit function

end if

writestring = true

end function

'讀出字串----------------------------

public function readstring(inifilename as string, section as string, key as string, size as long) as string

dim returnstr as string

dim returnlng as long

errormsg = vbnullstring

readstring = vbnullstring

if inifilename = "" then

errormsg = "ini file has not been specifyed!"

exit function

end if

returnstr = space(size)

returnlng = getprivateprofilestring(section, key, vbnullstring, returnstr, size, inifilename)

readstring = left(returnstr, returnlng)

end function

'讀出數值-----------------------------

public function readint(inifilename as string, section as string, key as string) as long

dim returnlng as long

readint = 0

errormsg = vbnullstring

if inifilename = "" then

errormsg = "ini file has not been specifyed!"

exit function

end if

returnlng = getprivateprofileint(section, key, 0, inifilename)

if returnlng = 0 then

returnlng = getprivateprofileint(section, key, 1, inifilename)

if returnlng = 1 then

errormsg = "can not read the ini file!"

exit function

end if

end if

readint = returnlng

end function 

讀取INI檔案

讀取ini檔案 ini ini new ini using system using system.text using system.runtime.interopservices namespace qf public string path 引用動態連線庫方法 dllimport kernel...

讀取ini檔案

自定義讀取ini檔案中的內容方法 鍵 值 private string contentvalue string section,string key 寫入ini檔案 節點名稱 如 typename 鍵 值 檔案路徑 dllimport kernel32 private static extern l...

讀取ini檔案

1.得到當前根目錄 import os 2.ini檔案組成 注釋內容 section部分 key value 多個 section 部分 可以有多個,但section不可重複 key value 多個 3.讀取ini檔案 3.1獲取ini檔案路徑 3.2匯入 configparser 3.3 先獲得...