真实基础中的全局数组

发布于 2024-08-16 20:22:13 字数 328 浏览 10 评论 0原文

关于使用“添加属性”创建在 realBASIC 项目中使用的全局数组有什么技巧吗?下图是我的尝试。

http://i17.photobucket.com/albums/b52/orubap /basic.jpg编辑:死链接)

使用 camModel(1) 编译并运行,但它不返回任何内容。使用 camModel(4) 会引发越界错误,所以我猜我已经完成了一半。

建议?

Any tips on creating a global array to use in a realBASIC project using 'add property'? Pictured below is my attempt.

http://i17.photobucket.com/albums/b52/orubap/basic.jpg (edit: dead link)

Using camModel(1) compiles and runs but it doesn't return anything. Using camModel(4) throws an out of bounds error so I'm guessing I'm half way there.

Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老街孤人 2024-08-23 20:22:13

即使代码可以编译,但这也不是初始化数组的有效方法。至少手册中没有提到这样做。我想说的是,编译器在这个问题上悄悄失败了,而不是将其标记为错误。您必须通过 init 方法放置这些值,例如在 App.Open 中。另外,不要忘记数组索引是从 0 开始的,即使在初始化期间也是如此。因此,按照您给出的代码声明三个值的数组属性:

camModel(2) as String

然后在 App.Open 事件中:

camModel(0) = "Nikon"
camModel(1) = "Sony"
camModel(2) = "Philips"

但是,如果是我这样做,我会这样声明该属性:

camModel(-1) as String

然后用 Array 函数填充:

camModel = Array("Nikon", "Sony", "Philips")

这样您可以稍后添加更多模型,而不必每次都与数组的边界混淆。

Even though the code compiles, that isn't a valid way of initializing an array. At the very least doing so isn't mentioned anywhere in the manuals. I would say that the compiler is quietly failing on that one, as opposed to flagging it as an error. You'll have to place the values via an init method, say in App.Open. Also, don't forget that array indexes are 0-based, even during initialization. So, going by the code you've given declare the array property for three values:

camModel(2) as String

and then in the App.Open event:

camModel(0) = "Nikon"
camModel(1) = "Sony"
camModel(2) = "Philips"

However, if it were me doing it, I would declare the property thus:

camModel(-1) as String

and then populate with the Array function:

camModel = Array("Nikon", "Sony", "Philips")

That way you can add more models later and not have to futz with the bounds of the array each time.

泅渡 2024-08-23 20:22:13

如果您想使用“添加属性”功能访问全局变量,只需创建一个新模块即可。然后,您可以向模块添加一个可以从任何地方访问的属性。

为了保持命名空间更干净,您可能需要限制对该属性的访问。 Global 将允许您仅使用 YourVariableName 访问该属性,但您也可以将权限更改为受保护(黄色三角形符号),因此您必须输入 YourModuleName.YourVariableName code> 访问变量。它让事情变得更干净一些。

因此,您可以通过创建模块轻松创建全局数组,然后单击“添加属性”并将 YourArrayName(-1) 声明为 Integer。您可以使用标准数组函数(ubound、append、remove 等)添加、删除和修改数组中的任何项目。

If you want to access a global variable using the "Add Property" function, just create a new Module. You can then add a property to the module that can be accessed from anywhere.

To keep your namespace cleaner, you might want to restrict access to the property. Global will allow you to access the property by just using YourVariableName, but you can also change the permissions to protected (the yellow triangle sign) so you'll have to type YourModuleName.YourVariableName to access the variable. It keeps things a little bit cleaner.

So you can easily create a global array by creating the module, then clicking Add Property and declaring YourArrayName(-1) as Integer for example. You can add, remove, and modify any of the items in the array using the standard array functions (ubound, append, remove, etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文