现在开发的项目需要有个ini文件读写的功能,但小弟没接触过VB,请高手救急!!
解决方案 »
- 求助这段搜索代码怎么写
- 请问如何使用Excecute方法通过http访问URL并将之下载到文本框中?????
- 在一个form中输入用户名,在另一form中调用怎样才能调用得到输入的这个用户名?
- 怎样动态绑定DataGrid?
- 请介绍一些较好的制作安装程序的工具
- 钩子阿钩子
- 数据库,小问题。
- 在DirectX8SDK中的VB程序示例为什么全是用的DX7?用法一样吗?
- 有哪位大师对win2000的TAPI30感兴趣的吗?请Please come in!
- access数据库存储长文本
- 请vb版朋友轻点鼠标帮忙投上你宝贵的一票,剪刀有礼了(散3000分)
- 如何判断CreateObject打开的应用程序,已经打开。
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 lpString As Any, _
ByVal lpFileName As String) As Long写Ini文件函数:
'---------------------------------------------------------------------------------------
' Procedure : subWriteINI
' Accept : [strHeadName] INI文件的表头,就是[]里的内容
' : [strListName] = 左边的名称
' : [strFileName] INI文件名
' : [strVal] = 右边的值
' : [strExplain] 说明,可选的
' Return :
' Purpose : 将信息写入Ini文件
'---------------------------------------------------------------------------------------
Public Sub subWriteINI(ByVal strHeadName As String, _
ByVal strListName As String, _
ByVal strFileName As String, _
ByVal strVal As String, _
Optional ByVal strExplain As String = "")
'如果是根目录,就直接当前目录加上文件名
If Right$(App.Path, 1) = "\" Then
strFileName = App.Path & strFileName
'如果非根目录,就是在当前目录和文件名中间加"\"
Else
strFileName = App.Path & "\" & strFileName
End If
'判断文件是否已经存在
If funExists(strFileName, vbNormal) = False Then
'如果文件不存在,则创建一个新的文件
Dim i As Integer
i = FreeFile
Open strFileName For Output As #i
Close #i
End If
Call WritePrivateProfileString(strHeadName, strListName, _
strVal & ";" & strExplain, strFileName)
End Sub
读Ini文件函数:
'---------------------------------------------------------------------------------------
' Procedure : funGetINI
' Accept : [strHeadName] INI文件的表头,就是[]里的内容
' : [strListName] = 左边的名称
' : [strFileName] INI文件名
' : [strDefault]
' Return :
' Purpose : 读INI文件过程
'---------------------------------------------------------------------------------------
Public Function funGetINI(ByVal strHeadName As String, _
ByVal strListName As String, _
ByVal strFileName As String, _
Optional ByVal strDefault As String = "") As String
Dim strVal As String * 2000
Dim strTemp As String
strVal = String(2000, Space(1))
Dim l As Long
If Right$(App.Path, 1) = "\" Then
strFileName = App.Path & strFileName
Else
strFileName = App.Path & "\" & strFileName
End If
l = GetPrivateProfileString(strHeadName, strListName, "", _
strVal, Len(strVal), strFileName)
strTemp = ""
If InStr(strVal, ";") > 0 Then
strTemp = Left$(strVal, InStr(strVal, ";") - 1)
End If
If strTemp = "" Then
funGetINI = strDefault
Else
funGetINI = strTemp
End If
End Function
例子:
如ini文件的名称为Config.ini内容如下:
[SQL SERVER]
LOGIN=82719005548271908444;
写ini文件:Call subWriteINI("SQL SERVER", "LOGIN", Config.ini,赋的新值 )
读ini文件:IniValue=funGetINI("SQL SERVER", "LOGIN", Config.ini, "")