怎么用VB简单的修改INI文件
我只想修改其中的几行,那个INI文件只有10行……,且INI在这个程序的文件夹里,要怎么写,我很菜,要解释,多给分!(例,INI的第一行=TEXT1.TEXT)...
我只想修改其中的几行,那个INI文件只有10行……,且INI在这个程序的文件夹里,要怎么写,我很菜,要解释,多给分!(例,INI的第一行=TEXT1.TEXT)
展开
5个回答
展开全部
Option Explicit
Private 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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName As String, ByVal KeyName As String, ByVal keydefault As String, ByVal Filename As String) As Long
Public Function myReadINI(inifile, inisection, inikey, iniDefault)
Dim lpApplicationName As String
Dim lpKeyName As String
Dim lpDefault As String
Dim lpReturnedString As String
Dim nSize As Long
Dim lpFilename As String
Dim RetVal As Long
Dim Filename As String
lpDefault = Space$(254)
lpDefault = iniDefault
lpReturnedString = Space$(254)
nSize = 254
lpFilename = inifile
lpApplicationName = inisection
lpKeyName = inikey
Filename = lpFilename
RetVal = GetPrivateProfileString(lpApplicationName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFilename)
myReadINI = lpReturnedString
End Function
Public Function myWriteINI(inifile As String, inisection As String, inikey As String, Info As String) As String
Dim RetVal As Long
RetVal = WritePrivateProfileString(inisection, inikey, Info, inifile)
myWriteINI = LTrim$(Str$(RetVal))
End Function
把以上的保存成个模块(bas文件)
然后程序里调用是这样的:
写ini:Call myWriteINI(app.path & "\test.ini", "Setup", "test", "数值")
读INI配置:变量 = myReadINI(App.Path & "\test.ini", "Setup", "test", "")
test.ini里的格式:
[Setup]
test=1234
Private 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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName As String, ByVal KeyName As String, ByVal keydefault As String, ByVal Filename As String) As Long
Public Function myReadINI(inifile, inisection, inikey, iniDefault)
Dim lpApplicationName As String
Dim lpKeyName As String
Dim lpDefault As String
Dim lpReturnedString As String
Dim nSize As Long
Dim lpFilename As String
Dim RetVal As Long
Dim Filename As String
lpDefault = Space$(254)
lpDefault = iniDefault
lpReturnedString = Space$(254)
nSize = 254
lpFilename = inifile
lpApplicationName = inisection
lpKeyName = inikey
Filename = lpFilename
RetVal = GetPrivateProfileString(lpApplicationName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFilename)
myReadINI = lpReturnedString
End Function
Public Function myWriteINI(inifile As String, inisection As String, inikey As String, Info As String) As String
Dim RetVal As Long
RetVal = WritePrivateProfileString(inisection, inikey, Info, inifile)
myWriteINI = LTrim$(Str$(RetVal))
End Function
把以上的保存成个模块(bas文件)
然后程序里调用是这样的:
写ini:Call myWriteINI(app.path & "\test.ini", "Setup", "test", "数值")
读INI配置:变量 = myReadINI(App.Path & "\test.ini", "Setup", "test", "")
test.ini里的格式:
[Setup]
test=1234
追问
我前面懂了,而且也编入了模块,请详细解释下后面的(从“然后程序里调用是这样的:
”往后),多给分!
追答
是调用过程
写INI用这个
Call myWriteINI(app.path & "\test.ini", "Setup", "test", "1234")
这个就会在当前程序路径下的test.ini里的[SETUP]段下test写入 数值
test.ini里面就是这样的了
[Setup]
test=1234
读INI里的值
dim main as string
main = myReadINI(App.Path & "\test.ini", "Setup", "test", "")
执行完了后,如果是上面的TEST.INI文件的话,那么MAIN="1234"
你把上面的保存成模块调用后,程序里想对INI读写操作就用这两条语句进行读写就可以了.
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
比较复杂,静下心来研究一下别人的程序,就会了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有专门的INI操作函数,全放在一个模块里,参考:
http://hi.baidu.com/51025187/blog/item/478322582fbd43ca9d8204f3.html
http://hi.baidu.com/51025187/blog/item/478322582fbd43ca9d8204f3.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
http://wenku.baidu.com/view/0c50830bbb68a98271fefaab.html
你看看吧,太多了,一句也说不清。
你看看吧,太多了,一句也说不清。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请参考 xjnzhidao 提供给您的网址,里面有详细注释,让不会的人也能看懂哦~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询