Hi, I'm having a go at trying to use classes.
Can anyone help me figure out what I did wrong here?
I defined a class (ClaFeature) and first I wrote a subroutine in a standard module which defined certained values of the class. Everything worked great.
Then I decided that I would be better served if I modified that subroutine and put it in the class module so I could use it as a method for that class:
I then wrote a sub in a standard module to test using the method, and when I step through, I'm getting a run-time error 424 object required.
The line thats highlighted is BPFeature.Define (rngItem)
Can anyone help me figure out what I did wrong here?
I defined a class (ClaFeature) and first I wrote a subroutine in a standard module which defined certained values of the class. Everything worked great.
Code:
Sub testClass()
Dim rngItem As Range
Dim BPFeature As ClaFeature
Set rngItem = Intersect(Range("A:A"), Selection.Rows.EntireRow)
If Not rngItem.Value = Empty Then
Set BPFeature = New ClaFeature
With BPFeature
.Item = rngItem.Value
.InputDescription = rngItem.Offset(0, 1).Value
.Nominal = rngItem.Offset(0, 2).Value
.HighTolerance = rngItem.Offset(0, 3).Value
.LowTolerance = rngItem.Offset(0, 4).Value
.Method = rngItem.Offset(0, 5).Value
.Zone = rngItem.Offset(0, 6).Value
If ThisWorkbook.Sheets("INPUT").Range("H2").Value = "METRIC" Then
.Metric = True
Else
.Metric = False
End If
End With
End If
End Sub
Then I decided that I would be better served if I modified that subroutine and put it in the class module so I could use it as a method for that class:
Code:
Sub Define(rngTarget As Range)
With Me
.Item = rngTarget.Value
.InputDescription = rngTarget.Offset(0, 1).Value
.Nominal = rngTarget.Offset(0, 2).Value
.HighTolerance = rngTarget.Offset(0, 3).Value
.LowTolerance = rngTarget.Offset(0, 4).Value
.Method = rngTarget.Offset(0, 5).Value
.Zone = rngTarget.Offset(0, 6).Value
If ThisWorkbook.Sheets("INPUT").Range("H2").Value = "METRIC" Then
.Metric = True
Else
.Metric = False
End If
End With
End Sub
I then wrote a sub in a standard module to test using the method, and when I step through, I'm getting a run-time error 424 object required.
The line thats highlighted is BPFeature.Define (rngItem)
Code:
Sub testDefine()
Dim rngItem As Range
Dim BPFeature As ClaFeature
Set rngItem = Intersect(Range("A:A"), ActiveCell.Rows.EntireRow)
If Not rngItem.Value = Empty Then
Set BPFeature = New ClaFeature
BPFeature.Define (rngItem) '<------error here
End If
End Sub