oop Programing quesiton....

  • Thread starter Thread starter John 3:16
  • Start date Start date
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
 
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
 
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.
 
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
 
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
 
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.
 
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
 
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
 
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.
 
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).
 
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#?
 
No, it wouldn't persist throughout the project, but Intellisense will often
fail if there's an error anywhere in the project.


Rob
 
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.
 
Back
Top