0

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. troubleshooting

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
  • You have a class hacked to be [VB_PredeclaredId = True](https://stackoverflow.com/a/34688164/11683). If that is indeed what you wanted, use it as a module, not as a class. – GSerg Jun 05 '20 at 17:31
  • You need `Set Me.insPt = insPt` and `Set Me.pAttr = Library.CreatePoint(0, 0, 0)`. – Brian M Stafford Jun 05 '20 at 17:36
  • Thanks for pointing out my bad assignments Brian. As for the attributes, this class had already existed, I'm just refactoring it to work with another CAD program besides ACAD. It has been a can of worms so far, it was a class that would sit on top of the ACAD ```ThisDocument``` class and somehow get run through a form. (honestly I've never seen it run and I'm not quite sure how it did). It definitely felt like a cross between a class and a module. Anyhow, I've set PredeclaredId to false but I still have the same error. You did however likely save me some trouble down the road so thank you. – Conrad Wiebe Jun 05 '20 at 18:08
  • Ah, I meant to say that I carried over the attributes from the last implementation without really knowing what they did. – Conrad Wiebe Jun 05 '20 at 18:09
  • Turns out your inputs actually did fix my 91 error, the error I was getting just now was 424 (object needed / not found). And it was because I had a spelling error :/ . So thanks for the help, this is answered – Conrad Wiebe Jun 05 '20 at 18:35

0 Answers0