Looks like
Msgbox MyWorkForm.sv_str_1
Is the culprit here. Does your Vb6 solution have Option Explicit set at the
top of the code page? You are attempting to TypeCast a form to form1 in a
manner like LateBinding. While this is fine for VB6, this isn't boding well
for .Net.
MyWorkForm is declared as a Form not as Form1, so when you want to access
properties and methods specific to a derived contract, you need to cast it
as such.
In C#, we use ((Form1)MyWorkform).sv_str_1
In VB.Net, I believe we use:
(CType(MyWorkForm, Form1)).sv_str_1
or
(DirectCast(MyWorkform, Form1)).sv_str_1
This should correct the issue at hand.
A lot of folks threw in "best practices", I am of the mind that as long as
it works for you, that is your best practice. However, I still feel that
there is a "better than others" approach to this scenario.
In my mind, when I hear "I need to share data values in two or more forms",
I immediately think of a class object or structure with some hot wiring for
sharing. But that is up to you.
You know folks are saying time and again that we (developers) need to get
that logic out of the UI and yet rarely do you see responses to posts with
MVP/MVC examples. Seems this just perpetuates the cycle. For many
developers there is no affect on them since they are Principles of
consulting firms that get paid to recover project that are failing or they
work in companies that have/havenot coding standards that address this. For
the rest of the denizens, there is little solice on the topic. So while I
threw in my approach, I didn't provide a sample piece of code because I
would suggest a MVP solution. And while I know this is a migration from VB6
to VB.Net and therefore a lot of work in tweaking the differences, folks
doing the migration shouldn't simply attempt to replicate functionality that
was in a working code base in the next gen compiler, they should be
attempting to maximize the features and "best practices" that brought out
the next gen compiler. And that requires the community to first agree on
"best practices" and then practice them in their community responses.
So for example:
VB6 allowed you to:
Dim MyForm as form
set MyForm = Form1
..Net suggests that you should:
Dim MyForm as form
MyForm = New Form1
Best Practices suggest you should:
Dim MyForm as IWinformFormView
MyForm = MyPresenter.CreateView(MyViews.FormView);
--The presenter (and not the form) then manages updating values between
views. The presenter then handles button clicks, so on and so forth.
--How/If you implement the MVP pattern is up to you. But we should all be
talking this way.
--Perhaps the forums aren't the best place, perhaps thecodeproject.com is
the only place to truely see this in action. But then, the community as a
whole isn't debunking/reinforcing one author's opinion of best practices.
"Young" <(E-Mail Removed)> wrote in message
news:49f14791$(E-Mail Removed)...
> Hi,
>
> I am currently porting a VB6 app to VB.NET 2008 and am stucked big tim.
>
> I've got 2 forms in VB.Net (Form1 and Form2) each with a public string
> variable defined as Dim sv_str_1 as string.
>
> I also got a Sub that accept a form and work on the variable.
>
> Eg.
>
> Sub DispValue(frm as form)
> Msgbox frm.sv_str_1
> End sub
>
> This will display whatever is in sv_str_1 for the form. Eg.
>
> 1) If I call DispValue(Form1), it will display sv_str_1 for Form1
> 2) Calling DispValue(Form2) will display sv_str_1 from Form2.
>
> This works in VB6 but not VB.Net.
>
> In VB6, I can also do this:
>
> Dim MyWorkForm as Form
> Set MyWorkForm = Form1
> Msgbox MyWorkForm.sv_str_1
>
> This will display the string value for Form1.
>
> In VB.NET, Msgbox MyWorkForm.sv_str_1 will generate an error when
> compiling - it says sv_str_1 is not a member of System.Windows.Forms.Form.
>
> This Msgbox Form1.sv_str_1 works in .NET because I did not assign Form1 to
> a variable.
>
> This is the same for accessing controls on a VB.NET form. For example, I
> can do this in VB6:
>
> Dim MyWorkForm as Form
> Set MyWorkForm = Form1
> Msgbox MyWorkForm.TextAdd.Text
>
> This will display the value for textbox "TextAdd"
>
> But same does not work in VB.NET. Same error. It says that TextAdd is not
> a member of System.Windows.Forms.Form.
>
> Is there a way around this?
>
> TIA
>
> Young
>
>
>
>
|