r(32))
lngRet = GetPrivateProfileString(strSection, strKey, "", strTmp, Len(strTmp), strINI)
strTmp = Trim(strTmp)
strTmp2 = ""
For I = 1 To Len(strTmp)
If Asc(Mid(strTmp, I, 1)) <> 0 Then
strTmp2 = strTmp2 + Mid(strTmp, I, 1)
End If
Next I
strTmp = strTmp2
GetIniKey = strTmp
End Function
Public Property Let INIFileName(ByVal New_IniPath As String)
'' Sets the new ini path
strINI = New_IniPath
End Property
Public Property Get INIFileName() As String
'' Returns the current ini path
INIFileName = strINI
End Property
''***************************************清除KeyWord"键"(Sub)***********************************************
Public Function DelIniKey(ByVal SectionName As String, ByVal KeyWord As String)
Dim RetVal As Integer
RetVal = WritePrivateProfileString(SectionName, KeyWord, 0&, strINI)
End Function
''如果是清除section就少写一个Key多一个""。
''**************************************清除 Section"段"(Sub)***********************************************
Public Function DelIniSec(ByVal SectionName As String) ''清除section
Dim RetVal As Integer
RetVal = WritePrivateProfileString(SectionName, 0&, "", strINI)
End Function
Form1中的内容:
Option Explicit
''一个绝对经典的在VB中操作.ini文件的通用类源代码示例
程序''
程序编写:中国青岛·许家国
'' 2002.6.16
''E-Mail: goj2000@163.com
''HomePage: http://www.gojclub.com
''定义一个.ini类型的变量
Dim DemoIni As New classIniFile
Private Sub Form_Load()
''对控件进行初始化
Text1.Text = "测试一下"
List1.Clear
''定义.ini文件名,并写入一些初始数据
DemoIni.INIFileName = App.Path & "\demoini.ini"
DemoIni.WriteIniKey "系统", "启动路径", App.Path
DemoIni.WriteIniKey "系统", "可执行
程序文件名", App.EXEName
''显示保存到.ini文件中的数据
Call CmdRead_Click
End Sub
''退出
程序Private Sub CmdExit_Click()
Unload Me
End Sub
''读取.ini文件中已经存在的数据并显示出来
Private Sub CmdRead_Click()
Dim TestStr As String
&nbs