VB 6 conversion

F

Fabrizio

Hi to all,
i'm pretty new on vb dotnet and I need your help.
with Vb 6 i was able to create a routine and use a form as parameter :
for example
Routine1 (frm as form)
frm.text1.value="TEST"
end sub

so that I can call this routine on different forms and be able to hv one
unique routine to update objects with same name on different forms.

I tried to update my project and vb net give me an error :
Object could not be resolved because it was within a generic namespace

Is there a way to solve this ?

Many thanks in advance
Fabrizio
 
A

Armin Zingler

Fabrizio said:
Hi to all,
i'm pretty new on vb dotnet and I need your help.
with Vb 6 i was able to create a routine and use a form as parameter
: for example
Routine1 (frm as form)
frm.text1.value="TEST"
end sub

so that I can call this routine on different forms and be able to hv
one unique routine to update objects with same name on different
forms.
I tried to update my project and vb net give me an error :
Object could not be resolved because it was within a generic
namespace
Is there a way to solve this ?



Routine1 (frm as ClassNameOfYourFormContainingText1)
frm.text1.value="TEST"
end sub


In VB6, the compiler didn't check the existence of the property which leads
to a runtime error if the form does not have such a property.


Armin
 
F

Fabrizio

Hi,
my routine is called from different forms And I didn't want to create a
unique routine for all forms.

Any othe suggestion ?

B.regartds
Fabrizio
 
A

Armin Zingler

Fabrizio said:
Hi,
my routine is called from different forms And I didn't want to create
a unique routine for all forms.

Any othe suggestion ?


That's what inheritance is used for: The common base type ensures the
existence of the Textbox. Maybe you can even put the sub in the common base
class, so you don't have to pass anything at all.

Armin
 
A

Armin Zingler

Fiammenghi Fabrizio said:
Hi,
sorry for bother... As I said I'm pretty new on dotnet.

I attach a very simple projct in vb 6.

Ummm.... yes.
How would you convert it in order to keep a unique routine (aggiorna)
that should update more than one form that hv the same objects ?

Concerning this sample project it's hard to say because both Forms (form2
and form3) are identic.

In VB.Net:
1. Design a form (called "BaseForm") containing the label and the button.
There you can also put "Sub aggiorna" - it doesn't need the argument because
the sub is already part of the Form.
2. Add two Forms (Form2 and Form3 related to the VB6 sample). In both,
change the line "Inherits System.Windows.Forms.Form" to "Inherits BaseForm"


Result:
http://people.freenet.de/armin.zingler/FormInheritance.zip
You have to build the exe before opening the Forms designer.

Maybe a Usercontrol is a better solution but this depends on what you
exactly want to do.


Armin
 
F

Fabrizio

Hi Armin,
many thanks for your help, I think I hv more or less understood your
example, but I find too difficult to integrate thhis kind of solution on my
project.

As per your example baseform is only used to create a "template" and it is
never used.
I tried to move controls on form2 and forms3, but I did not succeded and I
can only have them in the original position as in form1.
In add I can't find a way to change inheritance to an existing forms, but
only creating a new one I can specify (and apply) the inheritance.
The original project had several different routines that can be used inside
a form, so it would be difficult to create a unique form from wich I can
inherit obejcts.

If I don't find another solution I think that I hv to convert each single
routine, for each form I use, and if I hv to maintain a routine I hv to do
that in each form (crazy work).

Any other suggestion will be appreciated.

Best regards

Fabrizio
 
A

Armin Zingler

Fabrizio said:
Hi Armin,
many thanks for your help, I think I hv more or less understood your
example, but I find too difficult to integrate thhis kind of
solution on
my project.

As per your example baseform is only used to create a "template" and
it is never used.

It's not only a template, it's "part of" Form2 and Form3 due to inheritance.
As you see, I didn't have to add any code to Form2 and Form3.
I tried to move controls on form2 and forms3, but I did not succeded
and I can only have them in the original position as in form1.

That's why a usercontrol might make sense - but first see my question below.
In add I can't find a way to change inheritance to an existing
forms, but only creating a new one I can specify (and apply) the
inheritance. The original project had several different routines that
can be used inside a form, so it would be difficult to create a
unique form from wich I can inherit obejcts.


If I don't find another solution I think that I hv to convert each
single routine, for each form I use, and if I hv to maintain a
routine I hv to do that in each form (crazy work).

Another approach is to implement an interface in all these Forms. I don't
like the idea because you seem to have the same stuff in different Forms.
Then declare the argument type of the sub in question as your interface and
have the Forms return the textboxes or whatever via the interface. But,
again, this sounds like a Usercontrol placed on these Forms is the better
choice. Or (why) is this not possible?

Any other suggestion will be appreciated.


If you're coming from VB6, you should really rethink your design.

How can you be sure that the Form you pass to the Sub does have control(s)
with this name? What if the names differ? Could you describe two Forms that
have the same control(s) and that are passed to such a procedure?


Armin
 
F

Fabrizio

Hi Armin,
many thanks for your continued help.
My hd crashed and now I'm re-installing vs 6.
As soon as I finished I'll try to extract the 2 forms from my project.

As I already told, I'm at my first project with VB net and I "self" learnd
vb 6, so that's why I difficultly undestand your solution (like
usercontrol).

Regarding your questions, I designed my forms and I know which controls are
on them.
In add I created the first form, then the routine, and then I copied all the
controls I needed, (and used in the sub) from the first form to the second.

Maybe looking at the part of project I will send, probably you understand my
need.

At the moment if you hv time and you want to see my project running in vb 6
you can download it from http://www.grisusoft.it/Programmi-en.htm

Many tahnks in advance
Fabrizio
 
F

Fabrizio

Hi Armin,
many thanks for your continued help.
My hd crashed and now I'm re-installing vs 6.
As soon as I finished I'll try to extract the 2 forms from my project.

As I already told, I'm at my first project with VB net and I "self" learnd
vb 6, so that's why I difficultly undestand your solution (like
usercontrol).

Regarding your questions, I designed my forms and I know which controls are
on them.
In add I created the first form, then the routine, and then I copied all the
controls I needed, (and used in the sub) from the first form to the second.

Maybe looking at the part of project I will send, probably you understand my
need.

At the moment if you hv time and you want to see my project running in vb 6
you can download it from http://www.grisusoft.it/Programmi-en.htm

Many tahnks in advance
Fabrizio
 
A

Armin Zingler

Fabrizio said:
Hi Armin,
many thanks for your continued help.
My hd crashed and now I'm re-installing vs 6.

Ohhh.. :-(
As soon as I finished I'll try to extract the 2 forms from my
project.

As I already told, I'm at my first project with VB net and I
"self" learnd vb 6, so that's why I difficultly undestand your
solution (like
usercontrol).

If you have some controls that you want to use on more than one Form, you
can put them on a Usercontrol. Then place the Usercontrol on the Forms. The
code dealing with the controls on the Usercontrol are part of the
Usercontrol, so you don't have to copy or pass anything.
Regarding your questions, I designed my forms and I know which
controls are on them.
In add I created the first form, then the routine, and then I copied
all the controls I needed, (and used in the sub) from the first
form to the second.


Sounds like a Usercontrol is a good solution.

Maybe looking at the part of project I will send, probably you
understand my need.


I'll have a look. If possible, upload it on a server and post the link here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top