364,112 Members | 2160 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Calling functions from files

Amjad
P: n/a
Amjad
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


Chris, Master of All Things Insignificant
P: n/a
Chris, Master of All Things Insignificant
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" <Amjad@discussions.microsoft.com> wrote in message
news:89EB98EE-EE59-40BE-9B4F-07DA97933F07@microsoft.com...[color=blue]
> 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[/color]


Nov 21 '05 #2

Amjad
P: n/a
Amjad
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:
[color=blue]
> 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" <Amjad@discussions.microsoft.com> wrote in message
> news:89EB98EE-EE59-40BE-9B4F-07DA97933F07@microsoft.com...[color=green]
> > 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[/color]
>
>
>[/color]
Nov 21 '05 #3

Chris, Master of All Things Insignificant
P: n/a
Chris, Master of All Things Insignificant
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" <Amjad@discussions.microsoft.com> wrote in message
news:77632B75-E6CC-4EC4-B831-D50472EE19A2@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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" <Amjad@discussions.microsoft.com> wrote in message
>> news:89EB98EE-EE59-40BE-9B4F-07DA97933F07@microsoft.com...[color=darkred]
>> > 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[/color]
>>
>>
>>[/color][/color]


Nov 21 '05 #4

Greg Burns
P: n/a
Greg Burns
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:OGnepgT6EHA.3708@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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" <Amjad@discussions.microsoft.com> wrote in message
> news:77632B75-E6CC-4EC4-B831-D50472EE19A2@microsoft.com...[color=green]
>> 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:
>>[color=darkred]
>>> 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" <Amjad@discussions.microsoft.com> wrote in message
>>> news:89EB98EE-EE59-40BE-9B4F-07DA97933F07@microsoft.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
>>>
>>>
>>>[/color][/color]
>
>[/color]


Nov 21 '05 #5

Greg Burns
P: n/a
Greg Burns
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" <Amjad@discussions.microsoft.com> wrote in message
news:852E800A-FBC0-46EF-A02C-080DD0A38459@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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" <Amjad@discussions.microsoft.com> wrote in message
>> news:77632B75-E6CC-4EC4-B831-D50472EE19A2@microsoft.com...[color=darkred]
>> > 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" <Amjad@discussions.microsoft.com> wrote in message
>> >> news:89EB98EE-EE59-40BE-9B4F-07DA97933F07@microsoft.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
>> >>
>> >>
>> >>[/color]
>>
>>
>>[/color][/color]


Nov 21 '05 #6

Amjad
P: n/a
Amjad
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:
[color=blue]
> 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" <Amjad@discussions.microsoft.com> wrote in message
> news:852E800A-FBC0-46EF-A02C-080DD0A38459@microsoft.com...[color=green]
> > 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:
> >[color=darkred]
> >> 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" <Amjad@discussions.microsoft.com> wrote in message
> >> news:77632B75-E6CC-4EC4-B831-D50472EE19A2@microsoft.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" <Amjad@discussions.microsoft.com> wrote in message
> >> >> news:89EB98EE-EE59-40BE-9B4F-07DA97933F07@microsoft.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
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>[/color][/color]
>
>
>[/color]
Nov 21 '05 #7

Post your reply

Help answer this question



Didn't find the answer to your Visual Basic .NET question?

You can also browse similar questions: Visual Basic .NET