473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Accessing functions in a seperate codefile ?

Hi,

Sorry for the complete newb question, but none of the 3 books I own on C#
cover this.

If I place say, 10 or 15 functions in a codefile, what's the best method to
call these functions from say Form1.cs ?

thanks for all the help, I'm really trying here.
Nov 15 '05 #1
6 9749
Jimmy,

It depends on where you put them in a file. All of the functions that
you attached are part of a class. If they are static, then you can call the
method using the following code:

// Call a static method.
<typename>.<static method name>(<optional parameters>);

If the methods are instance methods, then you have to create an instance
of the type and then pass it to an instance of Form1 and then have Form1
access the methods internally.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jimmy" <Bu**@Burrrrp.com> wrote in message
news:3m*********************@news.easynews.com...
Hi,

Sorry for the complete newb question, but none of the 3 books I own on C#
cover this.

If I place say, 10 or 15 functions in a codefile, what's the best method to call these functions from say Form1.cs ?

thanks for all the help, I'm really trying here.

Nov 15 '05 #2
Jimmy <Bu**@Burrrrp.com> wrote:
Sorry for the complete newb question, but none of the 3 books I own on C#
cover this.

If I place say, 10 or 15 functions in a codefile, what's the best method to
call these functions from say Form1.cs ?

thanks for all the help, I'm really trying here.


You need to think in object-oriented terms. If the methods are static,
you just use ClassName.MethodName(). Otherwise, you'll need to have an
instance of the other type, and call the methods on that instance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
One way would be to create a class that holds your methods in another file
and to create an object of that class when you need to use the methods. For
example, if you have many methods that access a database you could do
something like:

//create a clsDataBase.cs file with all your database methods, then use it
clsDataBase db = new clsDataBase("Pass Any values needed for the constructor
here");
db.UpdateChildRows(rowsToUpdate);

Hope this helps

Marco

"Jimmy" <Bu**@Burrrrp.com> wrote in message
news:3m*********************@news.easynews.com...
Hi,

Sorry for the complete newb question, but none of the 3 books I own on C#
cover this.

If I place say, 10 or 15 functions in a codefile, what's the best method to call these functions from say Form1.cs ?

thanks for all the help, I'm really trying here.

Nov 15 '05 #4
Jimmy,

All functions must be members of a class, so you can either create a class
and make the functions members of it, then instantiate the class into an
object and call them, or move them into a Dll, annd essentially do the same
thing. Below is a way to move them into a Dll.

1) Try using: New->Project & choose Class library. This will create a Dll
assembly project. Put your functions in there as members of a class (or
classes, which ever makes the most organization sense).

2) I'm not certain "best way" can be answered directly, because the next
step depends upon the answer to the following question: Do you need to
dynamically load the Dll at run time, or can you statically access it?

I'll deal with the static approach, as it's easier, and should get you
started:
3) In your client app, set a reference to the Dll project.
4) Add an appropriate "using" statement at the top of your code file that
will be calling the Dll function(s) to include the namespace you set up in
the Dll. This assumes the namespace you created in the Dll is different from
the client app's namespace. If they share the same namespace, you won't need
this step.
5) Instantiate the object(s) you put into the dll and call the method(s) on
the object(s) in the client app. You don't have to do anything special
besides setting the reference and including the namespace.

If you need to dynamically load the Dlll and then retrieve the method(s) of
interest, this is more complicated and can become rather long winded. I'll
take a short cut on this one and recommend you look up"Loading Assemblies
into an Application Domain", "MethodInfo class" and then "Reflection" for
starters in MSDN. Those aught to point you in the right direction.

Hope this helps & good luck.

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com

"Jimmy" <Bu**@Burrrrp.com> wrote in message
news:3m*********************@news.easynews.com...
Hi,

Sorry for the complete newb question, but none of the 3 books I own on C#
cover this.

If I place say, 10 or 15 functions in a codefile, what's the best method to call these functions from say Form1.cs ?

thanks for all the help, I'm really trying here.

Nov 15 '05 #5

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
thanks for all the help, I'm really trying here.


You need to think in object-oriented terms. If the methods are static,
you just use ClassName.MethodName(). Otherwise, you'll need to have an
instance of the other type, and call the methods on that instance.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Excellent.

Thank you both, making the function static works in this situation, and
cured the problem.

Thanks for the help.
Nov 15 '05 #6
Thanks alot everyone for the very rapid responses with great examples, step
by steps, and links. I do appreciate the help and the kindness.
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Plankmeister | last post by:
Is it possible to access a function in a php document through a URL? For instance: http://www.somesiteorother.com/test.php?a_function And then have something like this in test.php: <?php ...
8
by: [RaZoR] | last post by:
hello, main script creates IE window, put an array there and then calls a child script. chils script makes an array element equal to some object and returns control to main script. then main...
3
by: Jeff Gaynor | last post by:
Hi, I am a moonlighting Java programmer who needs to get some JNI written in C. Thanks to legacy considerations, it must be in C. I hope I can frame this question in a way that you all can...
0
by: Rashad Rivera | last post by:
Hi Gang, My question is directed more towards the MS JSctip.NET dev team. I understand that you guys are planning to implement events in the newer versions of JS.NET, but is there a way to...
3
by: Anjali Lourda | last post by:
Hi, I have defined a function in global.asax file. Could somebody please tell me how i am supposed to call that function from the other files of the same project. Global.asax public function...
2
by: shaun duke | last post by:
I have been researching this over the last two days without success. I have a number of ultility functions that I want to make available to all pages. The pages will all be using code behind so...
0
by: Darrel | last post by:
This may be a dumb question, but... can an ASPX page access any classes or functions from a web project that it isn't explicitely a part of (ie, compiled with?) I'm building an app where I...
6
by: Ant | last post by:
I have the following code which works fine for running some tests defined within a module: def a_test(): print "Test A" def b_test(): print "Test B" if __name__ == "__main__":
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.