By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

Calling functions from files

P: n/a
Hi,
I want to make a project that calls and executes a function (VB code) made
in a seperate file in the Application Folder. I know I can create the
function in my project and call it internally, but I want to put the
function's code in an external file, so that future updates to the function
will require a replacing the function file instead of re-installing the whole
project.

Can you give me ideas on how I can make small updates to my application
project without uninstalling and then re-installing the whole project?

Thanks,
Amjad
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Make two projects. One that is a class library project. This will compile
to a dll. The other your executable. You can then reference these function
in your project and when you want to update the dll you can.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
Hi,
I want to make a project that calls and executes a function (VB code) made
in a seperate file in the Application Folder. I know I can create the
function in my project and call it internally, but I want to put the
function's code in an external file, so that future updates to the
function
will require a replacing the function file instead of re-installing the
whole
project.

Can you give me ideas on how I can make small updates to my application
project without uninstalling and then re-installing the whole project?

Thanks,
Amjad

Nov 21 '05 #2

P: n/a
Thanks for the idea.

- In order for the project to compile to a DLL, do I just include the
function's code in a module only? How do I make DLL files?
- Assuming that I made the DLL file. Can you give me an example on calling a
DLL file in my project?

Amjad

"Chris, Master of All Things Insignifican" wrote:
Make two projects. One that is a class library project. This will compile
to a dll. The other your executable. You can then reference these function
in your project and when you want to update the dll you can.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
Hi,
I want to make a project that calls and executes a function (VB code) made
in a seperate file in the Application Folder. I know I can create the
function in my project and call it internally, but I want to put the
function's code in an external file, so that future updates to the
function
will require a replacing the function file instead of re-installing the
whole
project.

Can you give me ideas on how I can make small updates to my application
project without uninstalling and then re-installing the whole project?

Thanks,
Amjad


Nov 21 '05 #3

P: n/a
To make the dll, open a new project. Instead of calling it a type "Windows
Application", make a Class Library instead. The easiest way to do this is
to make add a second project in the same solution.

All of the classes you use right now are dlls. System.Windows.Forms.Form
which is what inherit when you make a form for your windows application is
just a dll with the namespace of System.Windows.Forms. So when you make
your dll you can just reference by its name. For example.

In the second project which is a class library make a new class:

'Not Tested!
Public Class MathFunction

'This is shared so I don't have to make an instance of the class
Public Shared Function SquareNumber(Value as Integer) as Long
return Value * Value
End Sub

End Class

Now have your main form use it

Public Class MainForm
inherits Form

Private MainForm_Load(....) handles Me.Load
messagebox.Show(MathFunction.SquareNumber(5))
End Sub

End Class
That's the idea. Depending how you set things up you may have to reference
your new dll in your project. You also might want to give a namespace to
your class library. If they are in the same solution I don't think you'll
have any issues seeing you new class.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Thanks for the idea.

- In order for the project to compile to a DLL, do I just include the
function's code in a module only? How do I make DLL files?
- Assuming that I made the DLL file. Can you give me an example on calling
a
DLL file in my project?

Amjad

"Chris, Master of All Things Insignifican" wrote:
Make two projects. One that is a class library project. This will
compile
to a dll. The other your executable. You can then reference these
function
in your project and when you want to update the dll you can.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
> Hi,
> I want to make a project that calls and executes a function (VB code)
> made
> in a seperate file in the Application Folder. I know I can create the
> function in my project and call it internally, but I want to put the
> function's code in an external file, so that future updates to the
> function
> will require a replacing the function file instead of re-installing the
> whole
> project.
>
> Can you give me ideas on how I can make small updates to my application
> project without uninstalling and then re-installing the whole project?
>
> Thanks,
> Amjad


Nov 21 '05 #4

P: n/a
Just so you are aware (in case you don't see it)... the project type "Class
Library" is not available for all versions of VB.NET.

(There are work arounds).

Greg

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:OG**************@TK2MSFTNGP14.phx.gbl...
To make the dll, open a new project. Instead of calling it a type
"Windows Application", make a Class Library instead. The easiest way to
do this is to make add a second project in the same solution.

All of the classes you use right now are dlls. System.Windows.Forms.Form
which is what inherit when you make a form for your windows application is
just a dll with the namespace of System.Windows.Forms. So when you make
your dll you can just reference by its name. For example.

In the second project which is a class library make a new class:

'Not Tested!
Public Class MathFunction

'This is shared so I don't have to make an instance of the class
Public Shared Function SquareNumber(Value as Integer) as Long
return Value * Value
End Sub

End Class

Now have your main form use it

Public Class MainForm
inherits Form

Private MainForm_Load(....) handles Me.Load
messagebox.Show(MathFunction.SquareNumber(5))
End Sub

End Class
That's the idea. Depending how you set things up you may have to
reference your new dll in your project. You also might want to give a
namespace to your class library. If they are in the same solution I don't
think you'll have any issues seeing you new class.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
Thanks for the idea.

- In order for the project to compile to a DLL, do I just include the
function's code in a module only? How do I make DLL files?
- Assuming that I made the DLL file. Can you give me an example on
calling a
DLL file in my project?

Amjad

"Chris, Master of All Things Insignifican" wrote:
Make two projects. One that is a class library project. This will
compile
to a dll. The other your executable. You can then reference these
function
in your project and when you want to update the dll you can.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
> Hi,
> I want to make a project that calls and executes a function (VB code)
> made
> in a seperate file in the Application Folder. I know I can create the
> function in my project and call it internally, but I want to put the
> function's code in an external file, so that future updates to the
> function
> will require a replacing the function file instead of re-installing
> the
> whole
> project.
>
> Can you give me ideas on how I can make small updates to my
> application
> project without uninstalling and then re-installing the whole project?
>
> Thanks,
> Amjad


Nov 21 '05 #5

P: n/a
Open the References folder in your solution explorer for the Windows Form
project. On the Projects tab select you Class Library.

From code in your Windows Form try this:

Dim i as integer = ClassLibrary1.MathFunction.SomeSharedMethod()

"ClassLibrary1" is the root namespace of your Class Library project (unless
you changed it).

Greg
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
Thanks for the reply.

That idea makes sense. I created a "Class Library" project and a "Windows
Form" project in the same solution, however I'm unable to reference the
DLL
class in the Windows Form (i.e. "Name 'MathFunction' is not declared" in
your
code). Can you lead me to some online examples or documentation on how to
do
this?

Amjad

"Chris, Master of All Things Insignifican" wrote:
To make the dll, open a new project. Instead of calling it a type
"Windows
Application", make a Class Library instead. The easiest way to do this
is
to make add a second project in the same solution.

All of the classes you use right now are dlls. System.Windows.Forms.Form
which is what inherit when you make a form for your windows application
is
just a dll with the namespace of System.Windows.Forms. So when you make
your dll you can just reference by its name. For example.

In the second project which is a class library make a new class:

'Not Tested!
Public Class MathFunction

'This is shared so I don't have to make an instance of the class
Public Shared Function SquareNumber(Value as Integer) as Long
return Value * Value
End Sub

End Class

Now have your main form use it

Public Class MainForm
inherits Form

Private MainForm_Load(....) handles Me.Load
messagebox.Show(MathFunction.SquareNumber(5))
End Sub

End Class
That's the idea. Depending how you set things up you may have to
reference
your new dll in your project. You also might want to give a namespace to
your class library. If they are in the same solution I don't think
you'll
have any issues seeing you new class.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
> Thanks for the idea.
>
> - In order for the project to compile to a DLL, do I just include the
> function's code in a module only? How do I make DLL files?
> - Assuming that I made the DLL file. Can you give me an example on
> calling
> a
> DLL file in my project?
>
> Amjad
>
> "Chris, Master of All Things Insignifican" wrote:
>
>> Make two projects. One that is a class library project. This will
>> compile
>> to a dll. The other your executable. You can then reference these
>> function
>> in your project and when you want to update the dll you can.
>>
>> Chris
>>
>>
>> "Amjad" <Am***@discussions.microsoft.com> wrote in message
>> news:89**********************************@microsof t.com...
>> > Hi,
>> > I want to make a project that calls and executes a function (VB
>> > code)
>> > made
>> > in a seperate file in the Application Folder. I know I can create
>> > the
>> > function in my project and call it internally, but I want to put the
>> > function's code in an external file, so that future updates to the
>> > function
>> > will require a replacing the function file instead of re-installing
>> > the
>> > whole
>> > project.
>> >
>> > Can you give me ideas on how I can make small updates to my
>> > application
>> > project without uninstalling and then re-installing the whole
>> > project?
>> >
>> > Thanks,
>> > Amjad
>>
>>
>>


Nov 21 '05 #6

P: n/a
Thanks Greg.
I added my ClassLibrary1 to the References of my Windows Form project, and
now I can see the class and its methods within my windows form code.

That's what I was looking for.

Amjad

"Greg Burns" wrote:
Open the References folder in your solution explorer for the Windows Form
project. On the Projects tab select you Class Library.

From code in your Windows Form try this:

Dim i as integer = ClassLibrary1.MathFunction.SomeSharedMethod()

"ClassLibrary1" is the root namespace of your Class Library project (unless
you changed it).

Greg
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...
Thanks for the reply.

That idea makes sense. I created a "Class Library" project and a "Windows
Form" project in the same solution, however I'm unable to reference the
DLL
class in the Windows Form (i.e. "Name 'MathFunction' is not declared" in
your
code). Can you lead me to some online examples or documentation on how to
do
this?

Amjad

"Chris, Master of All Things Insignifican" wrote:
To make the dll, open a new project. Instead of calling it a type
"Windows
Application", make a Class Library instead. The easiest way to do this
is
to make add a second project in the same solution.

All of the classes you use right now are dlls. System.Windows.Forms.Form
which is what inherit when you make a form for your windows application
is
just a dll with the namespace of System.Windows.Forms. So when you make
your dll you can just reference by its name. For example.

In the second project which is a class library make a new class:

'Not Tested!
Public Class MathFunction

'This is shared so I don't have to make an instance of the class
Public Shared Function SquareNumber(Value as Integer) as Long
return Value * Value
End Sub

End Class

Now have your main form use it

Public Class MainForm
inherits Form

Private MainForm_Load(....) handles Me.Load
messagebox.Show(MathFunction.SquareNumber(5))
End Sub

End Class
That's the idea. Depending how you set things up you may have to
reference
your new dll in your project. You also might want to give a namespace to
your class library. If they are in the same solution I don't think
you'll
have any issues seeing you new class.

Chris
"Amjad" <Am***@discussions.microsoft.com> wrote in message
news:77**********************************@microsof t.com...
> Thanks for the idea.
>
> - In order for the project to compile to a DLL, do I just include the
> function's code in a module only? How do I make DLL files?
> - Assuming that I made the DLL file. Can you give me an example on
> calling
> a
> DLL file in my project?
>
> Amjad
>
> "Chris, Master of All Things Insignifican" wrote:
>
>> Make two projects. One that is a class library project. This will
>> compile
>> to a dll. The other your executable. You can then reference these
>> function
>> in your project and when you want to update the dll you can.
>>
>> Chris
>>
>>
>> "Amjad" <Am***@discussions.microsoft.com> wrote in message
>> news:89**********************************@microsof t.com...
>> > Hi,
>> > I want to make a project that calls and executes a function (VB
>> > code)
>> > made
>> > in a seperate file in the Application Folder. I know I can create
>> > the
>> > function in my project and call it internally, but I want to put the
>> > function's code in an external file, so that future updates to the
>> > function
>> > will require a replacing the function file instead of re-installing
>> > the
>> > whole
>> > project.
>> >
>> > Can you give me ideas on how I can make small updates to my
>> > application
>> > project without uninstalling and then re-installing the whole
>> > project?
>> >
>> > Thanks,
>> > Amjad
>>
>>
>>


Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.