永发信息网

用VB写一个类读写INI文件

答案:1  悬赏:0  手机版
解决时间 2021-07-20 09:50
  • 提问者网友:姑娘长的好罪过
  • 2021-07-19 14:38

老哥,我在网上找到下面这一个代码,我希望你能帮我做一个使用的实例,先谢谢了

详细内容请到

http://www.cnblogs.com/qcdnjeff/articles/1219074.html

Private IniFileName As String
Public ErrorMsg As String

Private Sub Class_Initialize()
IniFileName = vbNullString
ErrorMsg = vbNullString
End Sub

Public Sub SpecifyIni(FilePathName)
IniFileName = Trim(FilePathName)
End Sub

Private Function NoIniFile() As Boolean
NoIniFile = True
If IniFileName = vbNullString Then
ErrorMsg = "没有指定 INI 文件"
Exit Function
End If
ErrorMsg = vbNullString
NoIniFile = False
End Function

Public Function WriteString(Section As String, key As String, Value As String) As Boolean
WriteString = False
If NoIniFile() Then
Exit Function
End If
If WritePrivateProfileString(Section, key, Value, IniFileName) = 0 Then
ErrorMsg = "写入失败"
Exit Function
End If
WriteString = True
End Function

Public Function ReadString(Section As String, key As String, Size As Long) As String
Dim ReturnStr As String
Dim ReturnLng As Long
ReadString = vbNullString
If NoIniFile() Then
Exit Function
End If
ReturnStr = Space(Size)
ReturnLng = GetPrivateProfileString(Section, key, vbNullString, ReturnStr, Size, IniFileName)
ReadString = Left(ReturnStr, ReturnLng)
End Function

Public Function ReadInt(Section As String, key As String) As Long
Dim ReturnLng As Long
ReadInt = 0
ReturnLng = GetPrivateProfileInt(Section, key, 0, IniFileName)
If ReturnLng = 0 Then
ReturnLng = GetPrivateProfileInt(Section, key, 1, IniFileName)
If ReturnLng = 1 Then
ErrorMsg = "不能读取"
Exit Function
End If
End If
ReadInt = ReturnLng
End Function
详细

最佳答案
  • 五星知识达人网友:老鼠爱大米
  • 2021-07-19 14:50

不必写成一个类,我现在机器没有VB,写不了,你搜索一下读取INI的模块即可,不用非要写成类的!

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯