VB操作.ini后缀文件的方法

时间:2010-01-27 11:10:24  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:; 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 Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpA...
  正文:

读文件用到GetPrivateProfileString,写文件需要用到WritePrivateProfileString。
   在窗体放置两个命令按钮Command1与Command2,分别用来执行写操作与读操作。
Private 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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lphotoshop/ target=_blank class=infotextkey>pstring As Any, ByVal lpFileName As String) As Long


Private Sub Command1_Click()
Dim A As Long
'写信息
'修改ABC.INI文件中TIP字段中START的值为当前系统时间
'如果该文件不存在会自动建立,当函数返回值为0时说明修改不成功
A = WritePrivateProfileString("TIP", "START", Time$, App.Path & "ABC.INI")
If A = 0 Then MsgBox ("写文件时出错")
End Sub


Private Sub Command2_Click()
Dim A As Long
Dim T As String
'读取信息
T = Space$(1000) '事先定义读取值的字串宽度
'读取ABC.INI文件中TIP字段中START的值并打印出来
'当函数返回值为0时说明读取数据出错
A = GetPrivateProfileString("TIP", "START", "", T, 1000, App.Path & "ABC.INI")
If A = 0 Then MsgBox "找不到所需字段": Exit Sub
Print Left$(T, Len(Trim$(T)) - 1)
End Sub


"VB操作.ini后缀文件的方法"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/VB/12478.html


关键字:

关于《VB操作.ini后缀文件的方法》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td