无法在模块VB6中声明字符串

Nav*_*ron 0 vb6 vba

我正在尝试从遗留应用程序的文件中读取数据库字符串.为此,我将文件放在每个用户的AppData文件夹中.现在,我需要告诉应用程序文件的位置.但是,我似乎无法在模块中声明一个字符串(原始字符串在此模块中声明为常量).我怎么能克服这个?任何帮助,将不胜感激.

这是我试过的:

Dim loc As String
loc = Environ$("APPDATA")
Public Const CnnSTR = ReadIniValue(loc & "\PensionMaster\PM-Strings.ini", "DB", "DBSQL")
Run Code Online (Sandbox Code Playgroud)

但是我收到了"无效的外部程序"错误.

jac*_*jac 5

蒂姆威廉斯是对的.而不是试图将其声明为公共变量,而是创建公共函数或属性.我的偏好是在.bas模块中创建一个函数,在类中创建一个属性.

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
Run Code Online (Sandbox Code Playgroud)

要么

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
Run Code Online (Sandbox Code Playgroud)