为什么在一个 VB6 项目中声明的全局变量不会在同一 VB6 项目组中的另一个项目中编译?
我很抱歉这是一个如此基本的问题。
我们的 VB6 项目组包含 6 个项目以及包含所有应用程序表单的 UI 项目。
我们在其中一个表单后面的代码中生成一个 uniqueID (gstrUniqueImportUuid),该 ID 必须暴露给项目组中另一个项目中的类。
我尝试将此变量声明为 Common.bas 模块中的全局变量,该模块是主 UI 项目的一部分,如下所示:
Option Explicit
Public gstrUniqueImportUuid As String
然后我在表单中为 gstrUniqueImportUuid 分配一个值,效果很好。
但是,当我尝试在组中的其他项目之一中使用该全局变量的值时,该项目将无法编译 - “变量未定义”。
我到底做错了什么?
谢谢。
I apologize that this is such an elementary question.
Our VB6 project group contains 6 projects plus the UI project containing all the app's forms.
We generate a uniqueID (gstrUniqueImportUuid) in the code behind one of the forms, which must be exposed to a class in another project in the project group.
I've tried declaring this variable as a global variable in the Common.bas module that's part of the main UI project, like this:
Option Explicit
Public gstrUniqueImportUuid As String
I then assign a value to gstrUniqueImportUuid in the form, which works fine.
But then when I try to use that global variable's value in one of the other projects in the group, that project won't compile--"variable not defined".
What on earth am I doing wrong?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
模块在项目之外不公开。您想要做的是创建一个类并将其实例设置为 GlobalMultiUse。该类的任何公共属性对于引用该项目的任何项目都是可见的。请注意,您只能对 ActiveX DLL 和 ActiveX EXE 执行此操作。
Modules are not public outside of the Project. What you want to do is create a class and set it's instancing to GlobalMultiUse. Any public properties of that class will be visible to any project referencing that project. Note you con only do this for ActiveX DLLs and ActiveX EXEs.
我现在有点猜测,但是您尝试使用该变量的“其他项目”是否引用了“UI 项目”?必须在菜单project->references的引用列表中勾选Ui项目。
通常,UI 项目引用一个或多个其他项目,但反之则不然。即使变量是全局变量,也必须引用声明该变量的项目。
如果引用不存在并且您无法添加引用(您可能会获得循环依赖项),您可以将字段 gstrUniqueImportUuid 的声明移动到其他项目 .bas 文件之一。您将其移动到的项目(如果不是“其他项目”,则必须由 UI 项目(以及“其他项目”)引用
I'm guessing a bit now, but does the "other project" where you try to use the variable have a reference to the "UI project"? The Ui project must be checked in the references list in menu project->references.
Usually it's the UI project that is referencing one or more other projects but not the other way around. Even if the variable is global the project where it is declared in must be referenced.
If the reference doesn't exist and you can't add the reference (you might be getting circular dependencies) you can move the declaration of the field gstrUniqueImportUuid to one of the other projects .bas files. The project you move it to (if not the "other project" must be referenced to by the UI project (and the "other project")