其他分享
首页 > 其他分享> > VB 读写ini的代码

VB 读写ini的代码

作者:互联网

Attribute VB_Name = "Module1"
Option Explicit



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 Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
Const fName = "log.ini"
Const NongfName = "nong.ini"

Public Sub 写日志(年月 As String, 项 As String, 值 As String)
    Dim lng As Long
    lng = WritePrivateProfileString(年月, 项, 值, App.Path & "\" & fName)
End Sub

Public Function 读日志(年月 As String, 项 As String) As String
'读字符串
    Dim lng As Long
    Dim retstr As String
    retstr = String(260, 0)
    lng = GetPrivateProfileString(年月, 项, "", retstr, 256, App.Path & "\" & fName)
    retstr = Replace(retstr, Chr(0), "")

    读日志 = retstr
End Function

Public Sub 写农历(年月 As String, 项 As String, 值 As String)
    Dim lng As Long
    lng = WritePrivateProfileString(年月, 项, 值, App.Path & "\" & NongfName)
End Sub

Public Function 读农历(年月 As String, 项 As String) As String
'读字符串
    Dim lng As Long
    Dim retstr As String
    retstr = String(4, 0)
    lng = GetPrivateProfileString(年月, 项, "", retstr, 256, App.Path & "\" & NongfName)
    retstr = Replace(retstr, Chr(0), "")

    读农历 = retstr
End Function

标签:Function,VB,String,ByVal,读写,retstr,Long,ini,lng
来源: https://blog.csdn.net/laocooon/article/details/120177072