VBA读写ini 配置文件

Option Explicit
   'read
   Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" _
                 (ByVal lpApplicationName As String, _
                   ByVal lpKeyName As String, _
                   ByVal lpDefault As String, _
                   ByVal lpReturnedString As String, _
                   ByVal nSize As Long, _
                   ByVal lpFileName As String) As Long
   'write
   Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
                 (ByVal lpApplicationName As String, _
                   ByVal lpKeyName As String, _
                   ByVal lpString As String, _
                   ByVal lpFileName As String) As Long

Sub Read()
    Dim Rec As String
    Dim NC As Long
    
    Rec = String(255, 0)
    NC = GetPrivateProfileString("BOOT", "Shell", "", Rec, 255, "D:\test.ini")
    MsgBox Rec
    
End Sub

Sub WriteProfile()
    Dim NC As Long
    NC = WritePrivateProfileString("BOOT", "Shell", "Test1", "D:\test.ini")
End Sub

  

上一篇:计算kdj


下一篇:看看C# 6.0中那些语法糖都干了些什么(上篇)