VB中读取电脑文件做配置文件


'******下面是VB中声明读取电脑文件的系统函数,这个是以前老项目用的
'Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
'Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
'Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'**********跟同事问了一下,同事现在使用的这个
Declare Function GetPrivateProfileStringA& Lib "kernel32" (ByVal sec$, ByVal key$, ByVal default$, ByVal returnstr$, ByVal retsize&, ByVal fileName$)

‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘

Dim stractconn As String    '用这个作为中间变量存储读取的 关键字(key)内容 

’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
Function INIRead$(byval key$)
dim sRet$
sRet = String(255,Chr(0))

INIRead = Left(sRet, GetPrivateProfileStringa("load",key,"",sRet,Len(sRet),INI_PATH))

END FUNCTION
‘’‘’‘’‘’‘’‘’这个是放在电脑C盘根目录的配置文件,如有需求在这里更改‘’‘’‘’‘’‘’‘’‘’‘’‘
[load]

;读取本地库的数据源
activeconnetion1 = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=      ;Initial Catalog=      ;Data Source=    "

;读取远程库数据源
activeconnection2 ="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;PWD=      ;Initial Catalog='aaaa'; Data Source=        "

上一篇:算法系列15天速成——第十一天 树操作(上)


下一篇:【历史上的今天】2 月 3 日:“开源”一词诞生;比尔·盖茨发表《致电脑爱好者的公开信》;“雾件”问题被提出