我正在尝试从遗留应用程序的文件中读取数据库字符串。为此,我将文件放在每个用户的AppData文件夹中。现在,我需要告诉应用程序文件的位置。但是,我似乎无法在模块中声明一个字符串(原始字符串在此模块中声明为常量)。我怎么能克服这个?任何帮助将不胜感激。
这就是我的尝试:
Dim loc As String
loc = Environ$("APPDATA")
Public Const CnnSTR = ReadIniValue(loc & "\PensionMaster\PM-Strings.ini", "DB", "DBSQL")
但我收到了'无效的外部程序' 错误。
答案 0 :(得分:5)
Public Function GetCnnSTR() As String
Dim loc As String
Dim strPath as String
loc = Environ$("APPDATA")
strPath = ReadIniValue(loc & "\PensionMaster\PM-Strings.ini", "DB", "DBSQL")
GetCnnSTR = strPath
End Function
或
Public Property Get CnnSTR() As String
Dim loc As String
Dim strPath as String
loc = Environ$("APPDATA")
strPath = ReadIniValue(loc & "\PensionMaster\PM-Strings.ini", "DB", "DBSQL")
CnnSTR = strPath
End Property
答案 1 :(得分:0)
CnnSTR = ReadIniValue(Environ$("APPDATA") & "\PensionMaster\PM-Strings.ini", "DB", "DBSQL"
会工作吗?也许是Dim CnnSTR as String
行。
Const x=5
y = X
与
完全相同y=5