oop Programing quesiton....

J

John 3:16

Hello....
Not sure if this is the right newsgroup for this or not.
I'm trying to learn to migrate to using classes and oop.

Instead of referencing a form like

dim i as integer
i = Forms![MyForm].form.tbMyTextBox
docmd.openform("Form2")
Forms![Form2].form.inputparameters = i

How can I build and use a class like.....

dim a as new addr 'addr being a class
a.property1 = somevalue
docmd.openform("Form2")
Forms![Form2].form.inputparameters = a.property1

My problem is maintaing scope from form to form for the class.

Hopefully this description is clear enough for someone to shed
some light on this or point me in the right direction.

thanks,
bob mcclellan
 
V

Vadim Rapp

J> How can I build and use a class like.....

J> dim a as new addr 'addr being a class
J> a.property1 = somevalue
J> docmd.openform("Form2")
J> Forms![Form2].form.inputparameters = a.property1

J> My problem is maintaing scope from form to form for the class.

This can be accomplished by using Public Property in the form's code.


Vadim Rapp
 
J

John 3:16

Thanks for the reply Vadim
The Class property is declared as Public.
...but when you instanstiate a new class object, then
open the next form, the class is out of scope, so it's properties are out
of scope.
 
V

Vadim Rapp

Hello John:
You wrote on Thu, 8 Jun 2006 14:23:34 -0400:

J> Thanks for the reply Vadim
J> The Class property is declared as Public.
J> ..but when you instanstiate a new class object, then
J> open the next form, the class is out of scope, so it's properties are
J> out of scope.

Sorry, don't quite understand. In Access, you can't have more than one
instance of the same form. So you refer as forms!form1.myproperty=1.

Vadim
 
R

Robert Morley

Actually, in Access 2000 and beyond (and maybe 95/97, I forget), you most
certainly CAN have more than one instance of a form. You have to forego
using DoCmd.OpenForm, however, and instantiate the form directly. The code
below is vastly simplified, but would happily open two instances of the same
form.

Dim f1 As New MyForm
Dim f2 As New MyForm

f1.Visible = True
f1.SomeValue = "Form1"
f2.Visible = True
f2.SomeValue = "Form2"


Or in a class-based situation, you would simply instantiate the one form
with

Dim f1 As New MyForm
'Or more properly...
'Dim f1 As MyForm
'Set f1 As New MyForm
'... do stuff
'Set f1 = Nothing

Each instance of the class would then have its own instance of the form, f1
(which you can then echo out of the class as a property, or do whatever you
want to do with it).


Rob
 
J

John 3:16

Rob,
The objective I am trying to gain insight into is this.
Assume there is a class named Addrs
-one of the properties of Addrs is Addrs.A
-another property is Addrs.B
-one of it's method is Addrs.GetAddrName(s as string) as string

What I would like to learn how to do is this....

While working on a form.
dim Something as new Addrs
Addrs.a = SomeValue

THEN I want to open another form...
... execute Addrs.GetAddrName to populate Addrs.B with a value
from this 2nd form,

ON 2nd Form...
dim s as string
s = someValue
Something.b = Something.GetAddrName(s)

The problem I am experiencing is that the intellisense does
not acknowledge the existence of Something as an instanstiated class.
I just want to be able to allow the class to be the equivelant of
a global variable for lack of a better explanation.

I hope this explanation is clear.
Please bear with me on this and ask for further clarification if needed.

Thanks in advance,
bob.
 
V

Vadim Rapp

Hello Robert:
You wrote on Fri, 9 Jun 2006 14:37:53 -0400:

RM> Actually, in Access 2000 and beyond (and maybe 95/97, I forget), you
RM> most certainly CAN have more than one instance of a form.

Indeed, I did not even know. Cool. Then what's the problem.

f1.Visible = True
f2.Visible = True

f1.p1 = 3
f2.p1 = 4

Vadim
 
R

Robert Morley

I'm not sure why Intellisense wouldn't acknowledge it. The only time I've
seen it fail to acknowledge something is when there's a syntax error
somewhere in your code. Can you compile the entire project properly?



Rob
 
J

John 3:16

Yes....
It compiles fine.
are you saying that the new class declared in
one form should persist throughout the project?
I am new to oop and am trying to get my mind
around the concept.
Thanks in advance,
Bob.
 
S

Sylvain Lafontaine

If you want to learn OOP, VBA and Access are not the best place for doing
so. The implementation for custom OOP inside VBA is very, very limited and
the kind of things you are doing inside Access are usually simply to simple
to require OOP.

Objects in VBA are more like simple Structures with associated functions
than Objects; with no real possibility of inheritance, overloading of
operators, polymorphismm, virtual call, template, etc.

If you want to study OOP, you should take a more object oriented language
such as C++ (difficult but universal) or C# (much more simpler and strongly
connected to the .NET Framework; which is also the latest offering from
Microsoft for a development platform).
 
J

John 3:16

Thanks Sylvain.
I have built some .net webForms but used VB as opposed to C#.

In your opinion,
Is there limitations using VB instead of C#?
 
R

Robert Morley

No, it wouldn't persist throughout the project, but Intellisense will often
fail if there's an error anywhere in the project.


Rob
 
S

Sylvain Lafontaine

Yes, like C#, VB.NET is totally object oriented.

However, when building some .NET WebForms, you will learn more about the RAD
tools of Visual Studio than about OOP. The WebFormes themselves are objects
(in the same way that we may consider Access' Forms and Reports to be some
kind of object) bur learning to respond to events and display something in
HTML boxes is far from beeing a deep study of OOP concepts.

If you want to learn the intricacies of OOP, then you must attack a project
that will force you to write a lot of OOP code; for example writing a Road
Simulation or something like that.

Clicking with the mouse on a Properties Dialog Window is just that; even if
the window has been itself coded with OOP.
 

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