请教一下INI文件的操作

1984bobby 2006-03-22 02:52:13
小弟搜索了网上很多关于INI文件的读写等操作等文章,但实在看不懂,希望各位大侠指导一下

问题:
现在有一个窗体Frm1.frm,一个模块setdata.bas,setdata
模块setdata中存储程序中的数据库连接等信息,现在需要在程序启动的时候初始化程序的数据库连接,要求在系统启动的时候自动读入setdata.ini中的数据库文件路径赋予给setdata中的dbpath变量(方便生成连接字符串),就这么简单,只要演示让我明白ini文件的读入跟写入的过程让我明白就可以了,如果有好的教程麻烦贴个连接让小弟看看,不胜感激啊

...全文
112 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
hgw520 2006-03-24
[Dir Info]
OpenDir=C:\Documents and Settings\Administrator\桌面\test.txt
SaveDir=C:\Documents and Settings\Administrator\桌面\222.txt

[Dir Info] 是节名
OpenDir 是项名
C:\Documents and Settings\Administrator\桌面\test.txt 是写入的字符串
回复
hgw520 2006-03-24
GetPrivateProfileString("节名","项名","默认返回串","缓存",缓存大小,ini文件名)
WritePrivateProfileString("节名","项名","要写入字符串",ini文件名)
回复
1984bobby 2006-03-23
一楼的程序还是看得不太懂
回复
射天狼 2006-03-22
'INI文件操作函数
Private Declare Function GetPrivateProfileStringByKeyName& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName$, ByVal lpszKey$, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)
Private Declare Function GetPrivateProfileStringKeys& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName$, ByVal lpszKey&, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)
Private Declare Function GetPrivateProfileStringSections& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName&, ByVal lpszKey&, ByVal lpszDefault$, ByVal lpszReturnBuffer$, ByVal cchReturnBuffer&, ByVal lpszFile$)
Private Declare Function WritePrivateProfileStringByKeyName& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String)
Private Declare Function WritePrivateProfileStringToDeleteKey& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Long, ByVal lplFileName As String)
Private Declare Function WritePrivateProfileStringToDeleteSection& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Long, ByVal lpString As Long, ByVal lplFileName As String)

'***************************************************
'名称:GetIniStringValue
'功能:读取INI文件内容
'输入:Section:扇区;Key:键值;File:文件全路径
'输出:
'返回:键值数据
'***************************************************
Public Function GetIniStringValue(Section As String, Key As String, File As String) As String
Dim KeyValue As String
Dim characters As Long

KeyValue$ = String$(128, 0)
characters = GetPrivateProfileStringByKeyName(Section$, Key$, "", KeyValue$, 127, File$)

If characters > 1 Then
KeyValue$ = Left$(KeyValue$, characters)
End If

GetPrivateStringValue = KeyValue$
End Function

╭════════════════════════════╮
║                            ║
║  免费的学习、交流、源码、工具网站,欢迎大家访问!  ║
║  http://www.j2soft.cn/                ║
╰════════════════════════════╯
回复
faysky2 2006-03-22
这里的具体一点:
http://community.csdn.net/Expert/topic/4509/4509943.xml?temp=.5230219
回复
faysky2 2006-03-22
http://community.csdn.net/Expert/topic/4436/4436050.xml?temp=.248501
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2006-03-22 02:52
社区公告
暂无公告