I have written a similar enquiry to this newsgroup, but had no responses -
hence I will rephrase it with the hope that someone will answer.
I am new to using Classes, but trying hard to get the basics at the present
time, and seem to be winning.
Presently I am developing a Usercontrol for use in my application. To keep
it simple, let me give as an example - I have 3 command buttons in the User
Control. Each of these will have separate code in the click vent. However, I
wish to trigger a common event off in my external application once I press
one of these command buttons - i.e. I need to be able to create a new
instance of an existing class in my external application and send this
parameters. It may be a simple thing to do, but I am stuck - can soemone
send me a few clues as to how to achive this.
A few basic things on Classes that I need to get into my head:-
Is it bad practice to create n instance of class in the load event of a
form and re-use this?? Is best practice to create a new instance as and when
I need it.
Should I be setting the instance of the calss to Nothing once I have used
it.
I now understand about setting and getting the Properties within the Class
and using these properties in my application. The question is - can you do
the same with Methods, and if so how do you have acess to them externally,
or is this what I should be avoiding within a class? I was wondering whether
this was the way to go with my qustion at the top, but creating a Public Sub
in my Class does not expose it to my program.
Sorry if all the above appears rather obvious or silly to some. My
programming is set in the past, and may appear to be childish to others - I
am therefore trying to take this in hand, and to get Classes right from the
beginning. Anyone know of any useful on plain english links on Classes on
the Web?
Thanks in anticipation.
Paul Bromley 5 1166
Hello there, Is it bad practice to create n instance of class in the load event of a form and re-use this?? Is best practice to create a new instance as and when I need it.
There is nothing wrong in creating an instance of a class in any event, it
all depends on your usage. If the lifetime of the instance is to perform a
simple task and is limited to just the time inside your event then creating
an instance "locally" is fine.
Should I be setting the instance of the calss to Nothing once I have used it.
There is nothing wrong in setting the instance afterwards, it is a good
habit - as it clearly shows that you have finished with the instance of the
class. I don't think it guarantees that the memory is released for it
though.
I now understand about setting and getting the Properties within the Class and using these properties in my application. The question is - can you do the same with Methods, and if so how do you have acess to them externally, or is this what I should be avoiding within a class?
I prefer to use Property's and set-up the instance of the class up front.
Then call a function to perform an action e.g.
Dim Pic As New MyPicture
Pic.Width = 16
Pic.Height = 16
Pic.Load("etc.")
rather than:
Dim Pic As New MyPicture
Pic.Load("etc.", 16, 16)
Methods are only one way. Yes, you do need to set them as Public to be
called externally.
Also, I try to watch when writing Sub's and try to write Functions instead
(returning a boolean to indicate successful completion).
I was wondering whether this was the way to go with my qustion at the top, but creating a Public Sub in my Class does not expose it to my program.
What keyword are you using on your user control class? Is it Friend, public
or private?
Hope this helps,
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
-
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:e7**************@TK2MSFTNGP12.phx.gbl...I have written a similar enquiry to this newsgroup, but had no responses - hence I will rephrase it with the hope that someone will answer.
I am new to using Classes, but trying hard to get the basics at the present time, and seem to be winning.
Presently I am developing a Usercontrol for use in my application. To keep it simple, let me give as an example - I have 3 command buttons in the User Control. Each of these will have separate code in the click vent. However, I wish to trigger a common event off in my external application once I press one of these command buttons - i.e. I need to be able to create a new instance of an existing class in my external application and send this parameters. It may be a simple thing to do, but I am stuck - can soemone send me a few clues as to how to achive this.
A few basic things on Classes that I need to get into my head:-
Is it bad practice to create n instance of class in the load event of a form and re-use this?? Is best practice to create a new instance as and when I need it.
Should I be setting the instance of the calss to Nothing once I have used it.
I now understand about setting and getting the Properties within the Class and using these properties in my application. The question is - can you do the same with Methods, and if so how do you have acess to them externally, or is this what I should be avoiding within a class? I was wondering whether this was the way to go with my qustion at the top, but creating a Public Sub in my Class does not expose it to my program.
Sorry if all the above appears rather obvious or silly to some. My programming is set in the past, and may appear to be childish to others - I am therefore trying to take this in hand, and to get Classes right from the beginning. Anyone know of any useful on plain english links on Classes on the Web?
Thanks in anticipation.
Paul Bromley
Hi Simon,
Thanks for your help so far on this one. I am using Public on my User
Control class. I understand what you are saying so far. My problem still
remains unanswered - I have Command buttons in my suer control. Each of
these has different code in the click event. I also want each of these Click
events however to be able to Instantiate a new instance of a Class in my
external application. I can achive this if I place the Class within the User
Control, as there are references to the Class. I am unsure however how to
Intsnatiate the Class in my application however, where the class ideally
needs to be as I need my application to also access this class. Doing it the
way that I can get it to work at the moment would mean my placing the code
for my Class in the control and in my application. Hope that you understand
what I am saying here. It is driving me nuts, as I know that there must be a
more elegant solution to the Class code being in 2 places.
Many thanks if you or anyone else can help.
Best iwshes
Paul Bromley
"Simon Jefferies" <si***@cooltoolsonline.co.uk> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl... Hello there,
Is it bad practice to create n instance of class in the load event of a form and re-use this?? Is best practice to create a new instance as and when I need it.
There is nothing wrong in creating an instance of a class in any event, it all depends on your usage. If the lifetime of the instance is to perform a simple task and is limited to just the time inside your event then
creating an instance "locally" is fine.
Should I be setting the instance of the calss to Nothing once I have
used it. There is nothing wrong in setting the instance afterwards, it is a good habit - as it clearly shows that you have finished with the instance of
the class. I don't think it guarantees that the memory is released for it though.
I now understand about setting and getting the Properties within the
Class and using these properties in my application. The question is - can you
do the same with Methods, and if so how do you have acess to them
externally, or is this what I should be avoiding within a class? I prefer to use Property's and set-up the instance of the class up front. Then call a function to perform an action e.g.
Dim Pic As New MyPicture Pic.Width = 16 Pic.Height = 16 Pic.Load("etc.")
rather than:
Dim Pic As New MyPicture Pic.Load("etc.", 16, 16)
Methods are only one way. Yes, you do need to set them as Public to be called externally.
Also, I try to watch when writing Sub's and try to write Functions instead (returning a boolean to indicate successful completion).
I was wondering whether this was the way to go with my qustion at the top, but creating a Public Sub in my Class does not expose it to my program.
What keyword are you using on your user control class? Is it Friend,
public or private?
Hope this helps, Simon Jefferies Tools Programmer, Headfirst Productions mailto:si****@headfirst.co.uk
Hi Simon,
Thanks for your help so far on this one. I am using Public on my User
Control class. I understand what you are saying so far. My problem still
remains unanswered - I have Command buttons in my suer control. Each of
these has different code in the click event. I also want each of these Click
events however to be able to Instantiate a new instance of a Class in my
external application. I can achive this if I place the Class within the User
Control, as there are references to the Class. I am unsure however how to
Intsnatiate the Class in my application however, where the class ideally
needs to be as I need my application to also access this class. Doing it the
way that I can get it to work at the moment would mean my placing the code
for my Class in the control and in my application. Hope that you understand
what I am saying here. It is driving me nuts, as I know that there must be a
more elegant solution to the Class code being in 2 places.
Many thanks if you or anyone else can help.
Best iwshes
Paul Bromley
"Simon Jefferies" <si***@cooltoolsonline.co.uk> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl... Hello there,
Is it bad practice to create n instance of class in the load event of a form and re-use this?? Is best practice to create a new instance as and when I need it.
There is nothing wrong in creating an instance of a class in any event, it all depends on your usage. If the lifetime of the instance is to perform a simple task and is limited to just the time inside your event then
creating an instance "locally" is fine.
Should I be setting the instance of the calss to Nothing once I have
used it. There is nothing wrong in setting the instance afterwards, it is a good habit - as it clearly shows that you have finished with the instance of
the class. I don't think it guarantees that the memory is released for it though.
I now understand about setting and getting the Properties within the
Class and using these properties in my application. The question is - can you
do the same with Methods, and if so how do you have acess to them
externally, or is this what I should be avoiding within a class? I prefer to use Property's and set-up the instance of the class up front. Then call a function to perform an action e.g.
Dim Pic As New MyPicture Pic.Width = 16 Pic.Height = 16 Pic.Load("etc.")
rather than:
Dim Pic As New MyPicture Pic.Load("etc.", 16, 16)
Methods are only one way. Yes, you do need to set them as Public to be called externally.
Also, I try to watch when writing Sub's and try to write Functions instead (returning a boolean to indicate successful completion).
I was wondering whether this was the way to go with my qustion at the top, but creating a Public Sub in my Class does not expose it to my program.
What keyword are you using on your user control class? Is it Friend,
public or private?
Hope this helps, Simon Jefferies
Hello,
From my understanding I think you need to place a "reference" in your user
control. If you right click on references in the user control project, and
select Add Reference. From the Add Reference dialog, select the Projects
tab, select the external application from the list by double-clicking it.
This will now allow your user control project to have access to your classes
in the external application without having to include it etc.
Hope this helps further.
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
-
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message
news:ez**************@TK2MSFTNGP12.phx.gbl... Hi Simon,
Thanks for your help so far on this one. I am using Public on my User Control class. I understand what you are saying so far. My problem still remains unanswered - I have Command buttons in my suer control. Each of these has different code in the click event. I also want each of these Click events however to be able to Instantiate a new instance of a Class in my external application. I can achive this if I place the Class within the User Control, as there are references to the Class. I am unsure however how to Intsnatiate the Class in my application however, where the class ideally needs to be as I need my application to also access this class. Doing it the way that I can get it to work at the moment would mean my placing the code for my Class in the control and in my application. Hope that you understand what I am saying here. It is driving me nuts, as I know that there must be a more elegant solution to the Class code being in 2 places.
Many thanks if you or anyone else can help.
Best iwshes
Paul Bromley
"Simon Jefferies" <si***@cooltoolsonline.co.uk> wrote in message news:OQ**************@tk2msftngp13.phx.gbl... Hello there,
> Is it bad practice to create n instance of class in the load event of > a > form and re-use this?? Is best practice to create a new instance as and > when > I need it.
There is nothing wrong in creating an instance of a class in any event, it all depends on your usage. If the lifetime of the instance is to perform a simple task and is limited to just the time inside your event then creating an instance "locally" is fine.
> Should I be setting the instance of the calss to Nothing once I have used > it.
There is nothing wrong in setting the instance afterwards, it is a good habit - as it clearly shows that you have finished with the instance of the class. I don't think it guarantees that the memory is released for it though.
> I now understand about setting and getting the Properties within the Class > and using these properties in my application. The question is - can you do > the same with Methods, and if so how do you have acess to them externally, > or is this what I should be avoiding within a class?
I prefer to use Property's and set-up the instance of the class up front. Then call a function to perform an action e.g.
Dim Pic As New MyPicture Pic.Width = 16 Pic.Height = 16 Pic.Load("etc.")
rather than:
Dim Pic As New MyPicture Pic.Load("etc.", 16, 16)
Methods are only one way. Yes, you do need to set them as Public to be called externally.
Also, I try to watch when writing Sub's and try to write Functions instead (returning a boolean to indicate successful completion).
> I was wondering whether > this was the way to go with my qustion at the top, but creating a > Public > Sub > in my Class does not expose it to my program.
What keyword are you using on your user control class? Is it Friend, public or private?
Hope this helps, Simon Jefferies Tools Programmer, Headfirst Productions mailto:si****@headfirst.co.uk
Hi Simon,
Thanks for your help. The only way that I can manage to do this is by
compiling the class to a DLL, and referencing that. This works fine, but I
would have thought that there may have been a way of using the class
externally as it was.
Best wishes
Paul Bromley
"Simon Jefferies" <si***@cooltoolsonline.co.uk> wrote in message
news:Ol**************@TK2MSFTNGP11.phx.gbl... Hello,
From my understanding I think you need to place a "reference" in your user control. If you right click on references in the user control project, and select Add Reference. From the Add Reference dialog, select the Projects tab, select the external application from the list by double-clicking it.
This will now allow your user control project to have access to your
classes in the external application without having to include it etc.
Hope this helps further. Simon Jefferies Tools Programmer, Headfirst Productions mailto:si****@headfirst.co.uk -
"Paul Bromley" <fl*******@dsl.pipex.com> wrote in message news:ez**************@TK2MSFTNGP12.phx.gbl... Hi Simon,
Thanks for your help so far on this one. I am using Public on my User Control class. I understand what you are saying so far. My problem still remains unanswered - I have Command buttons in my suer control. Each of these has different code in the click event. I also want each of these Click events however to be able to Instantiate a new instance of a Class in my external application. I can achive this if I place the Class within the User Control, as there are references to the Class. I am unsure however how
to Intsnatiate the Class in my application however, where the class ideally needs to be as I need my application to also access this class. Doing it the way that I can get it to work at the moment would mean my placing the
code for my Class in the control and in my application. Hope that you understand what I am saying here. It is driving me nuts, as I know that there must
be a more elegant solution to the Class code being in 2 places.
Many thanks if you or anyone else can help.
Best iwshes
Paul Bromley
"Simon Jefferies" <si***@cooltoolsonline.co.uk> wrote in message news:OQ**************@tk2msftngp13.phx.gbl... Hello there,
> Is it bad practice to create n instance of class in the load event
of > a > form and re-use this?? Is best practice to create a new instance as
and > when > I need it.
There is nothing wrong in creating an instance of a class in any event, it all depends on your usage. If the lifetime of the instance is to
perform a simple task and is limited to just the time inside your event then creating an instance "locally" is fine.
> Should I be setting the instance of the calss to Nothing once I have used > it.
There is nothing wrong in setting the instance afterwards, it is a good habit - as it clearly shows that you have finished with the instance of the class. I don't think it guarantees that the memory is released for it though.
> I now understand about setting and getting the Properties within the Class > and using these properties in my application. The question is - can
you do > the same with Methods, and if so how do you have acess to them externally, > or is this what I should be avoiding within a class?
I prefer to use Property's and set-up the instance of the class up
front. Then call a function to perform an action e.g.
Dim Pic As New MyPicture Pic.Width = 16 Pic.Height = 16 Pic.Load("etc.")
rather than:
Dim Pic As New MyPicture Pic.Load("etc.", 16, 16)
Methods are only one way. Yes, you do need to set them as Public to be called externally.
Also, I try to watch when writing Sub's and try to write Functions instead (returning a boolean to indicate successful completion).
> I was wondering whether > this was the way to go with my qustion at the top, but creating a > Public > Sub > in my Class does not expose it to my program.
What keyword are you using on your user control class? Is it Friend, public or private?
Hope this helps, Simon Jefferies Tools Programmer, Headfirst Productions mailto:si****@headfirst.co.uk
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Patterson |
last post by:
I have noticed in the book of words that hasattr works by calling getattr
and raising an exception if no such attribute exists. If I need the value
in any case, am I better off using getattr...
|
by: J Peterman |
last post by:
I am trying to program a couple classes. One is called PositiveInteger and
is supposed to just store a positive integer. The second class is called
Circle, and is meant to describe a circle. Circle...
|
by: Ramesh |
last post by:
hi,
Let me ask some basic questions.
Can anybody explain me about the following questions:
1. When we have to create sn key? Whenever we compiled
Component we have to create or it is a one time...
|
by: p988 |
last post by:
Learning C# is much tougher than I expected...Please help me by answering
the following questions! Thank you in advance!
1. Are all Enumerations type Value type?
2. The line,
RegistryKey...
|
by: iTISTIC |
last post by:
Developing a new app and am trying to make this my first truly
OOP/3-Tier app. I understand the principles of the presentation,
business, and data layers. I do, however, have some questions on...
|
by: adriancico |
last post by:
Hi
I am working on a python app, an outliner(a window with a TreeCtrl
on the
left to select a document, and a RichTextBox at the right to edit the
current
doc).
I am familiarized with OOP...
|
by: Auddog |
last post by:
I'm new to working with classes. I'm pretty much a self taught php
programmer that uses php mostly for database entry and listings. I would
like to expand my talents and start working with...
|
by: Chris Asaipillai |
last post by:
Hi there
My compay has a number of Visual Basic 6 applications which are front endeed onto
either SQL Server or Microsoft Access databases.
Now we are in process of planning to re-write these...
|
by: MartinRinehart |
last post by:
Working on parser for my language, I see that all classes (Token,
Production, Statement, ...) have one thing in common. They all
maintain start and stop positions in the source text. So it seems...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |