是否可以在 openoffice 的用户类型中包含 Sub? VBA
Is it possibile to include Sub inside the user-Type in openoffice? VBA
User-Type是那种结构。我想知道我是否可以在其中包含子声明。类似于:
Type myType
myParam1 As String
myParam2 As Long
...
Sub mySub(param)
'here I want some code for printing/showing params value
End Sub
End Type
我问是因为当数据位于 myType 的项目数组中时,我在打印 myParam 值时遇到问题。用 myType 项目填充 myArr 后,声明
print myArr(i).myParam1
给我空字符串。
为了创建声明类型的数组,请务必使用 Dim As New
语法。
Type myType
myParam1 As String
myParam2 As Long
End Type
Sub mySub
Dim myArr(2) As New myType
myArr(0).myParam1 = "A"
myArr(0).myParam2 = 1
myArr(1).myParam1 = "B"
myArr(1).myParam2 = 2
For i = 0 to Ubound(myArr) - 1
Print myArr(i).myParam1
Next
End Sub
至于在 Type
语句中添加子例程,the documentation. On the other hand, that's an integral part of Python 是最流行的 LibreOffice 脚本语言之一。
class myClass:
myAttr1 = ""
myAttr2 = 0
def myFunc(self, param):
self.myAttr2 = param
print(self.myAttr1)
myArr = [myClass(), myClass()]
myArr[0].myAttr1 = "A"
myArr[0].myAttr2 = 1
myArr[1].myAttr1 = "B"
myArr[1].myAttr2 = 2
for myObj in myArr:
myObj.myFunc(3)
User-Type是那种结构。我想知道我是否可以在其中包含子声明。类似于:
Type myType
myParam1 As String
myParam2 As Long
...
Sub mySub(param)
'here I want some code for printing/showing params value
End Sub
End Type
我问是因为当数据位于 myType 的项目数组中时,我在打印 myParam 值时遇到问题。用 myType 项目填充 myArr 后,声明
print myArr(i).myParam1
给我空字符串。
为了创建声明类型的数组,请务必使用 Dim As New
语法。
Type myType
myParam1 As String
myParam2 As Long
End Type
Sub mySub
Dim myArr(2) As New myType
myArr(0).myParam1 = "A"
myArr(0).myParam2 = 1
myArr(1).myParam1 = "B"
myArr(1).myParam2 = 2
For i = 0 to Ubound(myArr) - 1
Print myArr(i).myParam1
Next
End Sub
至于在 Type
语句中添加子例程,the documentation. On the other hand, that's an integral part of Python 是最流行的 LibreOffice 脚本语言之一。
class myClass:
myAttr1 = ""
myAttr2 = 0
def myFunc(self, param):
self.myAttr2 = param
print(self.myAttr1)
myArr = [myClass(), myClass()]
myArr[0].myAttr1 = "A"
myArr[0].myAttr2 = 1
myArr[1].myAttr1 = "B"
myArr[1].myAttr2 = 2
for myObj in myArr:
myObj.myFunc(3)