VB读取.INI文件内容
- 点滴记录
- 2020-11-24
- 3141
逛论坛的时候,学到的技能,读INI文件界面能够读取和写入.INI文件代码如下:首先插入个模块,然后复制粘贴下面的代码'读配置文件(调用系统库函数 Public...
逛论坛的时候,学到的技能,读INI文件
界面能够读取和写入.INI文件
代码如下:
首先插入个模块,然后复制粘贴下面的代码
'读配置文件(调用系统库函数)
Public Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName As String, ByVal KeyName As String, ByVal lpDefault As String, ByVal lpReturnString As String, ByVal nSize As Long, ByVal FileName As String)
'写配置文件(调用系统库函数)
Public Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keyDefault$, ByVal FileName$)
'读配置文件(简化函数调用)
Public Function ReadIni(ByVal AppName As String, ByVal KeyName As String, ByVal DefaultValue As String, Optional IniPath As String) As String
Dim Buf As String
Dim ret As Integer
Dim tmp As String
Buf = String(1024, 0) 'buf=1024个0
If IniPath = "" Then
ret = GetPrivateProfileString(AppName, KeyName, DefaultValue, Buf, 1024, App.Path + "\config.ini")
Else
ret = GetPrivateProfileString(AppName, KeyName, DefaultValue, Buf, 1024, IniPath)
End If
tmp = Mid(Buf, 1, ret)
If InStr(1, tmp, Chr(0)) > 0 Then tmp = Left(tmp, InStr(1, tmp, Chr(0)) - 1)
ReadIni = tmp
End Function
'写配置文件(简化函数调用)
Public Function WriteIni(ByVal AppName As String, ByVal KeyName As String, ByVal KeyValue As String, Optional IniPath As String = "") As Boolean
If IniPath = "" Then
WritePrivateProfileString& AppName, KeyName, KeyValue, App.Path + "\config.ini"
Else
WritePrivateProfileString& AppName, KeyName, KeyValue, IniPath
End If
End Function
然后在窗体下复制粘贴下面的代码
Private Sub Command1_Click()
WriteIni "系统设置", "系统名称", Text2.Text '写入ini的操作
MsgBox "ok"
Form_Load
End Sub
Private Sub Form_Load()
Text1.Text = ReadIni("系统设置", "系统名称", " ") '读取ini的操作
Form1.Caption = soft_name
End Sub
本文链接:http://zxmcloud.com/?id=30
上一篇:基于B语言设计的电子礼单
下一篇:vb检测更新文件
发表评论