# Re: 如何自制INI档，让VB程式起动时读取INI VALUE 呢？

Posted by 小v on May 15, 1999 at 09:20:41:

In Reply to: 如何自制INI档，让VB程式起动时读取INI VALUE 呢？ posted by VAIO on May 14, 1999 at 21:20:49:

: 如何自制INI档，让VB程式起动时读取INI VALUE 呢？

'读取.INI档宣告(读取lpReturnedString会在后面加上chr(0))
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
'写入.INI档宣告
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

读取范例:(传回值放入buff变数)
RET=GetPrivateProfileString("FORMSIZE", _
"TOP", "0", buff,, "C:\INI\FORM_1.INI")
写入范例:
WritePrivateProfileString "FORMSIZE", "TOP", _
1300, "c:\INI\form_1.INI"

FORM_1.INI档案内容:
[FORMSIZE]
TOP=1300
LEFT=100
WIDTH=8900
HEIGHT=7200

Follow Ups: