LibreOffice Basic 忽略我的“某些”类型...结束类型定义

LibreOffice Basic Ignoring “some” of my Type...End Type Definition

我正在使用 LibreOffice 版本:4.4.3.2 构建 ID:40m0(Build:2) 区域设置:en_AU

我有一个基本模块

在这个模块的顶部,在我拥有的任何子函数或函数之前

Type InitHeadings
    MySort_By As Integer
    MyCharacter As Integer
    MyInitiative As Integer
    MyRolled As Integer
    MyTotal As Integer
End Type

...

Global InitiativeColumn As New InitHeadings

但是当我 运行 设置一个断点和 'watch' InitiativeColumn 对象时,只显示前两个字段。

我的其余代码与此 struct 相关,正如文档所称的那样。我没有在其他任何地方引用它。谁能告诉我为什么前两个会起作用而其余的不起作用?我在这段代码中还有另外两个 structs 并且都忽略了最后三个字段。这是 Bug 吗?

Sub Main
'Initialise Doc and Sheet Objects

Dim Doc As Object

Doc = ThisComponent
StatsSheet = Doc.Sheets.getByName("Stats")
InitiativeSheet = Doc.Sheets.getByName("Initiative")
CombatSheet = Doc.Sheets.getByName("Combat")


'LOAD HEADING NAMES
'Initiative Sheet
    For Column = 0 to 25 'Columns A to Z
        MyHeadingName = InitiativeSheet.getCellByPosition(Column,0).String
        Select Case MyHeadingName
        Case "Sort By"
            InitiativeColumn.MySort_By = Column
        Case "Character"
            InitiativeColumn.MyCharacter = Column
        Case "Initiative"
            InitiativeColumn.MyInitiative = Column
        Case "Rolled"
            InitiativeColumn.MyRolled = Column
        Case "Total"
            InitiativeColumn.MyTotal = Column
        End Select
    Next Column

End Sub


Sub MyInitiativeButton

'Iterate over a range of cells:
For Row = 1 To 25 'Rows 2 to 26
    'Column 3 is column D the "Rolled" column
    InitiativeSheet.getCellByPosition(InitiativeColumn.MyRolled,Row).VALUE = Roledice(1,20,0)
Next Row

End Sub

它看起来像一个错误,似乎已被报告 here。我在较新的版本(LO 5.1.0.3)中测试时没有出现问题。

这只是调试器的问题 window。值仍然存在:

Sub TestStructs
    InitiativeColumn.MySort_By = 5
    InitiativeColumn.MyCharacter = 5
    InitiativeColumn.MyTotal = 5
    InitiativeColumn.DoesntExist = 5
End Sub

此代码在第 InitiativeColumn.DoesntExist = 5 行之前工作正常,随后崩溃。

现在你在评论中提到的Global问题确实是个问题。考虑到 global variables are bad 的标准编程建议,我认为考虑替代方案是明智的。

您可以使用 returns InitiativeColumnFunction 而不是子例程吗?如果没有,那么按照您的建议分配变量似乎是一个可行的解决方法。就我个人而言,对于 LO 宏,我更喜欢 Python 或 Java,因为它们具有 类.