I have several Class Modules in my Workbook. One of public functions in Class Module 1 relies on data from a function in Class Module 2, this happens four times. In the event that the object is missing from Class 2 the program crashes (as expected). I am having difficulty debugging the code properly as it seems that I can only exit the program from the main subroutine. I would prefer to kill the program from the Class function, but I don't know if that is possible (we can squash this here if it is). I am currently using On Error statements in the main subroutine, but these don't execute in a timely manner because the function in Class 1 gets data from Class 2 four times.
Class Module 1 Function
Function oload(ByVal pload As Double, ByVal cord As cCordCol, ByVal grid As cGridCol)
' cord is a scripting.dictionary of Class Module Objects (cCord)
' grid is a scripting.dictionary of Class Module Objects (cGrid)
n1 = grid.Item(pg1).toGlobal(cord)
n2 = grid.Item(pg2).toGlobal(cord)
n3 = grid.Item(pg3).toGlobal(cord)
n4 = grid.Item(pg4).toGlobal(cord)
' do something here
oload = sum_Ploads
End Function
Above the n1 thru n4 is where I am calling on the public function of Class Module 2.
Below is the Class Module 2 Function
Function toGlobal(ByVal cord As cCordCol)
On Error Resume Next
ctype = cord.Item(Me.cord1).sys
' Missing Coordinate System Error
If Err.Number <> 0 Then
i = MsgBox("The definition of Coordinate " & Me.cord1 & " was missing from the Bulk Data " & Chr(10) & _
"File. Include this Coord in the .bdf and re-execute the program.", vbOKOnly, "Runtime Error")
' *** TERMINATE MAIN SUBROUTING HERE ***
End If
This will raise a message box indicating that an object was missing, specifically the (me.cord1) part - this is an item in a scripting.dictionary. I want to terminate the program here.
The main subroutine (greatly reduced) is here:
Sub main()
' lookup Element ID, Calc OLOAD, Sum Load Set OLOAD
On Error GoTo PROC_ERR
If dict_quad.Exists(EID) Then dict_oload.Item(LS).add_to_oload (dict_quad.Item(EID).oload(pload, dict_cord, dict_grid))
If dict_tria.Exists(EID) Then dict_oload.Item(LS).add_to_oload (dict_tria.Item(EID).oload(pload, dict_cord, dict_grid))
PROC_ERR:
If Err.Number <> 0 Then Exit Sub
End Sub
I have a lot of nested operations here. You can see the "goto" statement won't execute until the "oload" function is complete. The "oload" function calls upon the "toGlobal" function four times before it finishes its calculations.
How can I terminate the subroutine after the first occurance of a missing object in the "toGlobal" function?