标题:ini文件的建立与读取
只看楼主
jsbinghe
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-6-23
 问题点数:0 回复次数:0 
ini文件的建立与读取

这是在其他论坛上看到,特在此共享一下。呵呵

虽然进入win95之後,一般读写ini文件被读写Registry所取代,但我们还是可以透过
win31的传统方式读写ini文件,以存程式目前的相关设定,而於下一次程式执行时再
读回来。目前建议使用GetSetting SaveSetting的方式存於Registry中,不用目前
的方式。 储存程式的设定
'请於form中放3个TextBox,一个CommandBox
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 lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, _
ByVal lpFileName As String) As Long

Private Sub Command1_Click()
Dim success As Long
success = WritePrivateProfileString("MyApp", "text1", Text1.Text, "c:\aa.ini")
'叁数一 Section Name
'叁数二 於.ini中的项目
'叁数三 项目的内容
'叁数四 .ini文件的名称
success = WritePrivateProfileString("MyApp", "text2", Text2.Text, "c:\aa.ini")
success = WritePrivateProfileString("MyApp2", "text3", Text3.Text, "c:\aa.ini")
End Sub

Private Sub Form_load()
Dim ret As Long
Dim buff As String
buff = String(255, 0)
ret = GetPrivateProfileString("Myapp", "text1", "text1", buff, 256, "c:\aa.ini")
'若.ini MyApp中无text1,则采用叁数三的值
Text1.Text = buff
buff = String(255, 0)
ret = GetPrivateProfileString("Myapp", "text2", "text2", buff, 256, "c:\aa.ini")
Text2.Text = buff
buff = String(255, 0)
ret = GetPrivateProfileString("Myapp2", "text3", "text3", buff, 256, "c:\aa.ini")
Text3.Text = buff
End Sub

搜索更多相关主题的帖子: ini文件 程式 Registry form 
2007-09-02 23:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-167263-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.977304 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved