So I am creating a custom class meant to model a terminal block (tb) and just finished (without testing) the methods used to draw and add attributes to it. Now trying to test the class's methods I ran this:
Function CreateTerminalBlock(Name As String, rows As Integer, cols As Integer) As CommonProjects.tb
Set CreateTerminalBlock = New CommonProjects.tb
CreateTerminalBlock.init Name, Library.CreatePoint(0, 0, 0), rows, cols
End Function
Sub test()
CreateTerminalBlock "test", 4, 4
End Sub
I get an error on the line where I call init
on the new tb. Judging off this it's apparent that CreateTerminalBlock is not actually being assigned correctly but hovering over CommonProjects.tb
gave me a message that confused me.
As for what the class looks like, its my first time working with one in VBA so pointers are appreciated. I was surprised to see that if I set a var to private other members in the same class became blind to it, hence them all being public. I also felt that using Set / Get properties made it messier, and more confusing personally since I have yet to use them.
tbClass:
Attribute VB_Name = "tb"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = True
Const tbHeight = 0.3125
Const tbWidth = 1.25
Const tbColWidth = 3.5
Const textHeight1 = .2
Const textHeight2 = .156
Public tBlock As Block
Public rows As Integer
Public cols As Integer
Public tbName As String
Public insPt As Point
Public blockInfo As AttributeDef
Public pAttr As Point
Sub init(tbName As String, insPt As Point, rows As Integer, cols As Integer)
Me.rows = row
Me.cols = col
Me.tbName = tbName
Me.insPt = insPt
Me.pAttr = Library.CreatePoint(0, 0, 0)
Set tBlock = ActiveDocument.Blocks.Add(pAttr, tbName)
Dim layer6 As Layer
For Each docLayer in ActiveDocument.Layers
If docLayer.Name = "6" Then
Set layer6 = docLayer
GoTo layerExists
End If
Next
Set layer6 = ActiveDocument.Layers.Add(6)
layerExists:
layer6.Color = Library.CreateColor(6)
AddTBAttributes
AddTerminals
End Sub