如何能够象FISHEDIT一样,可以读取*.INI的数据呢?
我希望作一个这样的东西
---------------------------------------------------------------------------------------------------
保存在[A.INI]的
120 200 1 30 (类似这样的数据)
然后VB由来读取出,然后放入四个变量中,如
dim a,b,c as int
a=120
b=200
c=1
d=30
------------------------------------------------------------------------------------------------------
我在网上发现一个模块,但是自己不会用,他的格式是GetINI(ByRef inifile As String, ByVal section As String, ByVal key As String, Optional ByVal defvalue As String = vbNullString)这样的调用事件
注释中写:'inifile string ini文件名
'section string ini文件中的段落
'key string ini文件的关键字
'defvalue string ini文件中的值,输入时取空值
但是我还是用不来...晕~~
---------------------------------------------------------------------------------------------------------
模块原码如下:- Option Explicit
- Public 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
- Public 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
- Public 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
- '读
- '输入
- 'inifile string ini文件名
- 'section string ini文件中的段落
- 'key string ini文件的关键字
- 'defvalue string ini文件中的值,输入时取空值
- '输出
- 'getini string 取得的ini文件中的值
- Public Function GetINI(ByRef inifile As String, ByVal section As String, ByVal key As String, Optional ByVal defvalue As String = vbNullString) As String
- Dim stemp As String * 256
- Dim nlen As Integer
- stemp = Space$(256)
- nlen = GetPrivateProfileString(section, key, defvalue, stemp, 255, App.Path & "" & inifile)
- GetINI = Left$(stemp, nlen)
- End Function
- '写
- 'inifile string ini文件名
- 'section string ini文件中的段落
- 'key string ini文件的关键字
- 'value string ini文件中的值,可以是数字字符串
- Public Sub WriteINI(ByRef inifile As String, ByVal section As String, ByVal key As String, ByVal value As String)
- Dim x As Long, buff As String * 256, i As Integer
- buff = value + Chr(0)
- x = WritePrivateProfileString(section, key, buff, App.Path & "" & inifile)
- End Sub
复制代码 --------------------------------------------------------------------------------------------------------------------------------------------
现在问题是
1.如何靠以上的模块读取INI里的指定的数据?
2.如何调用此模块?此模块还有其他的作用吗?
以上一个问题300,全部回答600两,第一个回答正确者拿分. |