I am in the process of converting a VB6 application with 60 forms to VB.Net. Each form has many public variables, instead of properties.
Many public subs and functions can work with several different forms. I could not keep the form type variables as it obviously would not compile. I first tried to use an Interface but then learned they don't support variables. Now I have an abstract form class which I am adding the methods and functions as overridable. Now it is complaining that the abstract form doesn't contain the controls of the child form.
I created a function which returns the abstract class, returning the child form class depending on the form's name, passed through my abstract form class. Now, I want to use that returned child form class in a public function but it complains because I have not DirectCast it to that child form class which has the controls.
I wish I could have a conditional right-side assignment, and am trying to figure how to use DirectCast with a select-case statement.
I am stuck in a function that used to take a simple System.Windows.Forms.Form that would work with any form passed to it, and compiling was not a problem. Now in a more strict environment I need to pass in any one of several forms and then have an object variable of the child class form. I believe I want to DirectCast it once and which there was a variable / logical way I could use one DirectCast that would cast it to the correct child class.
An example of what won't compile, my form1 and form2 both have a txtFirstName control.
Public Function Test() As
Dim f As f_AbstractForm 'any form that calls this
f = GetFormByName(f.Name) 'returns child form object which inherits f_AbstractForm, function return type is f_AbstractForm
' Next line is the problem.
' Compiler doesn't like that txtFirstName is not on f_AbstractForm, so I need to DirectCast before this line,
' but stuck on how to do this. If form1 calls Test() then I want it to return a form1, if form2 calls Test() then I need it to return form2
f.txtFirstName.Text = ""
This is my first post since joining Experts Exchange, any help or advice will be appreciated!