明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1806|回复: 1

[建议] VB读取INI文件很有用, 可以直接读取指定文件行

[复制链接]
发表于 2005-6-2 21:57:00 | 显示全部楼层 |阅读模式
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

Public Function ReadIni(ByVal file As String, ByVal section As String, _
ByVal key As String, ByVal default As String) As String

Dim x As Long
Dim sSection As String, sEntry As String, sDefault As String
Dim sRetBuf As String, iLenBuf As Integer, sFileName As String 'Six arguments
sSection$ = section
sEntry$ = key
sDefault$ = default
sRetBuf$ = String$(256, 0) '256 null character
iLenBuf% = Len(sRetBuf$)
sFileName$ = file

'function will return a value of 12 in this case
x = GetPrivateProfileString(sSection$, sEntry$, sDefault$, sRetBuf$, iLenBuf%, sFileName$)

'sValue$ will contain the string 'PACKARD BELL'
sValue$ = Left$(sRetBuf$, x)

'return value
ReadIni = sValue$
End Function Sub Test_ReadIni()
MsgBox ReadIni("d:\test.ini", "TEST", "2", "null")
End Sub 文件d:\test.ini的内容: [test]
1=hello
2=world
3=!
发表于 2005-6-2 23:25:00 | 显示全部楼层
不过用程序读写INI文件都很麻烦,而且Windows几乎经把ini这种保存信息形式抛弃了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 14:49 , Processed in 0.170309 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表