daves22406
Technical User
I have a form (NewForm) that is inherited from a base form (BaseForm). There are several types of NewForm, all of which inherit from BaseForm. Each NewForm contains a method called Calculate. When I click on a button on NewForm, it opens another form (GraphForm) and passes NewForm as a property (PassedForm) of GraphForm so that the Calculate method can be used (along with several other properties of NewForm). My question is, how do I call the Calculate method of NewForm from GraphForm? The code below is obviously not complete, but you should be able to get the idea:
in BaseForm:
Protected Overridable Function Calculate() as Single
' override in NewForm
End Function
in NewForm:
Protected Overrides Function Calculate() as Single
'do calculations here
End Function
Button_Click event:
Dim frm as New GraphForm
frm.PassedForm = Me
frm.Show
in GraphForm:
Private Property PassedForm as BaseForm
Dim answer as single = PassedForm.Calculate
When Calculate is called from the GraphForm, the Calculate function in BaseForm is exectuted. Is this because GraphForm.PassedForm is declared as type BaseForm, so only public methods in BaseForm are available? How would I execute the Calculate function in NewForm from GraphForm? Is there a better way to do this than passing NewForm to GraphForm?
in BaseForm:
Protected Overridable Function Calculate() as Single
' override in NewForm
End Function
in NewForm:
Protected Overrides Function Calculate() as Single
'do calculations here
End Function
Button_Click event:
Dim frm as New GraphForm
frm.PassedForm = Me
frm.Show
in GraphForm:
Private Property PassedForm as BaseForm
Dim answer as single = PassedForm.Calculate
When Calculate is called from the GraphForm, the Calculate function in BaseForm is exectuted. Is this because GraphForm.PassedForm is declared as type BaseForm, so only public methods in BaseForm are available? How would I execute the Calculate function in NewForm from GraphForm? Is there a better way to do this than passing NewForm to GraphForm?