VB读写配置文件

 

 

 

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
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

Private Sub Form_Load()
Dim StrName As String, Strtemp As String

'写入信息
StrName = "jacky"
WritePrivateProfileString "Config", "Key", StrName, App.Path + "\config.ini"
End Sub

Private Sub command1_Click()
Dim msg As String
'读取信息
msg = Space(255)
GetPrivateProfileString "Config", "Key", "000", msg, 255, App.Path + "\config.ini"
MsgBox msg
End Sub

 

 

-----------------结果会在根目录下生成config.ini文件----------------

内容为:

[Config]
Key=jacky

你可能感兴趣的:(VB读写配置ini文件)