主题:[讨论]vb6.0读写INI文件!!!
chenjun302
[专家分:80] 发布于 2008-06-24 08:55:00
VB怎么写INI 如:
aaa.ini的内容
[updata]
num=103
写之后是
[updata]
num =104
[em18][em18][em18]
回复列表 (共4个回复)
沙发
okbaby [专家分:100] 发布于 2008-06-24 09:52:00
使用API函数,google里搜搜。
板凳
shifta [专家分:380] 发布于 2008-06-24 13:24:00
先声明API函数:
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
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
下面举例说明函数用法:
如果要读写ini文件中的以下内容:
[QueryDate]
StartDate=2006-03-17
EndDate=2006-03-18
Dim strSdate As String, strEdate As String
读取ini文件
strSdate = Space$(11)
strEdate = Space$(11)
tmpG = GetPrivateProfileString("QueryDate", "StartDate", "", strSdate, 11, App.Path & "\main.ini")
tmpG = GetPrivateProfileString("QueryDate", "EndDate", "", strEdate, 11, App.Path & "\main.ini")
写入ini文件:
tmpW = WritePrivateProfileString("QueryDate", "StartDate", "2006-03-17", App.Path & "\main.ini")
tmpW = WritePrivateProfileString("QueryDate", "EndDate", "2006-03-18", App.Path & "\main.ini")
3 楼
jianghongbo1 [专家分:410] 发布于 2008-06-25 08:38:00
写
dim i as integer
open app.path & "aaa.ini" for inpute as #1
for i=1 to leng(text1.text)
print #1,mid(text1.text,i,1)
next
close #1
读
dim str as string
open app.path & "aaa.ini" for inpute as #1
do while eof(1)=false
str=inpute(1,1)
str=str &
loop
close #1
text1.text=str
4 楼
crackdung [专家分:650] 发布于 2008-06-25 21:53:00
[quote]先声明API函数:
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
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
下面举例说明函数用法:
如果要读写ini文件中的以下内容:
[QueryDate]
StartDate=2006-03-17
EndDate=2006-03-18
Dim strSdate As String, strEdate As String
读取ini文件
strSdate = Space$(11)
strEdate = Space$(11)
tmpG = GetPrivateProfileString("QueryDate", "StartDate", "", strSdate, 11, App.Path & "\main.ini")
tmpG = GetPrivateProfileString("QueryDate", "EndDate", "", strEdate, 11, App.Path & "\main.ini")
写入ini文件:
tmpW = WritePrivateProfileString("QueryDate", "StartDate", "2006-03-17", App.Path & "\main.ini")
tmpW = WritePrivateProfileString("QueryDate", "EndDate", "2006-03-18", App.Path & "\main.ini")
[/quote]
此方法会好一些,我使用很久了
我来回复