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

上一篇:私有化轻量级持续集成部署方案--02-Nginx网关服务


下一篇:数组和循环结合的小案例