Big problem with a method

cuisancio

Member
Joined
Mar 7, 2006
Messages
11
Programming Experience
Beginner
Hello, I have to migrate a VB6 app to VB .net and i've found a very big problem with a method.

The situation is this:

I have a method who takes a form as parameter

Public Function Update(ByRef f_called As System.windows.forms.form, ByRef rst As ADODB.Recordset, ByRef Mode As String) As Boolean


[...]

f_called.insert_register()
f_called.modify_register()


[...]

End Function

This method uses, as you see, some methods of the forms.
The problem is that it runs in VB6 but not in VB. net: "Object could not be resolved because it was within a generic namespace"

A week ago, i found a "temporal" solution because only a form (form2) used that method, the solution was:

Public Function Update(ByRef f_called As System.windows.forms.form, ByRef rst As ADODB.Recordset, ByRef Mode As String) As Boolean

Dim fcall As form2
fcall = CType(f_called, form2)

[...]

fcall.insert_register()
fcall.modify_register()

And it runs well... but now, there are other forms that also have to use that method...

I thought in something like this:

Public Function Update(ByRef f_called As System.windows.forms.form, ByRef rst As ADODB.Recordset, ByRef Mode As String) As Boolean

If f_called.GetType.Name.Equals("form2") Then
Dim fcall As form2
fcall = CType(f_called, form2)
Else if
f_called.GetType.Name.Equals("form3") Then
Dim fcall As form3
fcall = CType(f_called, form3)
[...]

fcall.insert_register()
fcall.modify_register()

But VB.net doens't let me compile this :(

I thought another solution: create a class called Father with the methods insert_register() and modify_register() like this:

Public Class Father
Inherits System.Windows.Forms.Form

Function Modify_Register() As Boolean
MsgBox("THIS IS THE FATHER")
Return False
End Function

Function Insert_Register() As Boolean
MsgBox("THIS IS THE FATHER")
Return False
End Function
End Class


And then i put:

Public Class Form2
Inherits Father
(instead of System.Windows.Forms.Form)ANDPublic Class Form3
Inherits Father
(instead of System.Windows.Forms.Form)
But when the app execute the method

Public Function Update(ByRef f_called As Father, ByRef rst As ADODB.Recordset, ByRef Mode As String) As Boolean
[...]

f_called.insert_register()
f_called.modify_register()


[...]

End Function

It executes the methods in the father class instead of the children class, as i wanted, showing the "THIS IS THE FATHER" message :(

How can i execute the children methods???????????? (Solutions as "Do a cast" let me in the original situation)

I'll be very grateful.
 
Well, I think i've found the solution... i've put this:

Public Class Father
Inherits System.Windows.Forms.Form

Public Overridable Function Modify_Register() As Boolean
MsgBox("THIS IS THE FATHER")
Return False
End Function

Public Overridable Function Insert_Register() As Boolean
MsgBox("THIS IS THE FATHER")
Return False
End Function
End Class

And in the method of the forms, i added the word Overrides.
 
Back
Top