请问在VB6.0中,怎样读写和生成.ini配置文件?

请问在VB6.0中,怎样读写和生成.ini配置文件?请给也详细的代码并作出解释,谢谢!老大,能不能给点中文注解啊,我很菜啊。... 请问在VB6.0中,怎样读写和生成.ini配置文件?请给也详细的代码并作出解释,谢谢!
老大,能不能给点中文注解啊,我很菜啊。
展开
 我来答
liujiayu10
2007-05-25 · TA获得超过354个赞
知道答主
回答量:590
采纳率:0%
帮助的人:0
展开全部
给你一个类,专门读写INI的

classIniFile.cls:

Option Explicit

Private strINI As String
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 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 Function MakePath(ByVal strDrv As String, ByVal strDir As String) As String
Do While Right$(strDrv, 1) = "\"
strDrv = Left$(strDrv, Len(strDrv) - 1)
Loop

Do While Left$(strDir, 1) = "\"
strDir = Mid$(strDir, 2)
Loop

MakePath = strDrv & "\" & strDir
End Function

Private Sub CreateIni(strDrv As String, strDir As String)
strINI = MakePath(strDrv, strDir)
End Sub

Public Sub WriteIniKey(strSection As String, strKey As String, strValue As String)
WritePrivateProfileString strSection, strKey, strValue, strINI
End Sub

Public Function GetIniKey(strSection As String, strKey As String) As String
Dim strTmp As String
Dim lngRet As String
Dim I As Integer
Dim strTmp2 As String

strTmp = String$(1024, Chr(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)
strINI = New_IniPath
End Property

Public Property Get INIFileName() As String
INIFileName = strINI
End Property

Public Function DelIniKey(ByVal SectionName As String, ByVal KeyWord As String)
Dim RetVal As Integer
RetVal = WritePrivateProfileString(SectionName, KeyWord, 0&, strINI)
End Function

Public Function DelIniSec(ByVal SectionName As String)
Dim RetVal As Integer
RetVal = WritePrivateProfileString(SectionName, 0&, "", strINI)
End Function

示例:

Dim myIni As New classIniFile
Const myinifile = "\mail.ini"
myIni.INIFileName = App.Path & myinifile
myIni.WriteIniKey "mail", "pop3", pop3
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式