VB对INI文件操作
VB对INI文件操作
2009-02-25 00:17
INI 文件是什么样子?——不会吧,这都不知道。INI 文件就是 Windows 中常见
的以 .ini 为扩展名的文件,其内部格式和各部分的名称如下:
[Section1]
Key1=Value1
Key2=Value2
Key3=Vlaue3
[Section2]
Key1=Value1
Key2=Value5
Key4=Value4
Key5=...
...
INI 文件中分若干个段 (Section),每个段中有若干个键 (Key) 值 (Value) 对
。一个键值对保存一个信息;段则将属性类似的一些键值对组织在一起。同一个段中不
能出现两次以上同样的键,但不同的段中可以出现相同的键。
现在明白了吗?要是还不明白,就到 Windows 里找两个 INI 文件看看,文本编辑
器就可以打开的。明白了 INI 文件就要开始学习怎样在 VB 中读写 INI 了。
VB 读写 INI 文件,难吗?不难,因为 Windows 已经为我们做好了一切,我们只
需要调用它的 API 函数就可以了。为了读写 INI 文件,我们可能用到以下 API 函数
:
GetPrivateProfileInt
GetPrivateProfileString
WritePrivateProfileString
其中 WritePrivateProfileString 是用来向 INI 文件写信息的,而
GetPrivateProfileInt 和 GetPrivateProfileString 则是用来从 INI 文件中读信息
的,前者用于读取整型数据,后者则用于读取字符串型数据。
上述三个 API 函数在 VB 中的申明和说明如下:
Private Declare Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileIntA" ( _ ' 返回所读取的长整型值
ByVal lpApplicationName As String, _ ' 要读取的段 (Section) 名称
ByVal lpKeyName As String, _ ' 要读取的的键 (Key) 名称
ByVal nDefault As Long, _ ' 指定默认值,如果读取时出错,
则返回该值
ByVal lpFileName As String) As Long
相关文档:
看了别人写的C#的 自己转了一下 然后后重新改了改 写成了这个
另外还有一个我写的验证日期是否合法的代码 在后面 都是vb的 c#只会看不会写
'判断闰年=======================
Private Function CheckLeap(ByVal year As Integer) As Boolean
If (year Mod 4 = 0) AndAlso (year Mod 100 <> ......
Option Explicit
Function Delete3(Arr As Variant) As Variant
Dim i As Integer
For i = LBound(Arr) To UBound(Arr)
If i > UBound(Arr) Then Exit For
If Arr(i) = 3 Then
Do
Dim j As Integer
For j = i To UBound(Arr) - 1
......
Welcome to Microsoft Developer Support, Languages team blog! You will find a lot of language related troubleshooting resources here.
Troubleshooting PInvoke Related Issues
I am back with some more PInvoke Stuff. Recently I was working on a PInvoke issue which I found interesting ......
【函数】
GetFileVersionInfo
【操作系统】
Win9X:Yes
WinNT:Yes
【声明】
GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" &n ......
不能直接使用CopyMemoryStr,应该将字符串转为byte数组,然后使用CopyMemory
Property Get item() As String
If h = 0 Then ErrRaise ERROR_INVALID_DATA
'BugAssert p <> pNull
Dim c As Long, ptr0 As Long
Dim ab() As Byte
& ......