VB对于*.ini的读取问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 20:33:02
如题
注意:请勿复制 粘贴一大串,那样没分
如果我看懂了的话,我会追分~

比如你的aaa.ini文件结构是这样的:
[Section1]
parm1 = 123
parm2 = WXYZ

用API浏览器(VB中自带的,程序组里面有)
1.用Public Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long 来读取ini文件里的整数参数.
比如:num = GetPrivateProfileInt("Section1","parm1",0,"aaa.ini")
执行后num的值应该就是123了. 倒数第2个参数是缺省值,这里我写成0.如果函数没有读到你需要的参数,则num就为缺省值.

依此类推,还有
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
可以读区字符串参数.
比如:
dim ret as string*20
GetPrivateProfileString "Section1","parm2","AAA",ret,20,&qu