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

Function and Class question

P: n/a
Hello,
I have 2 questions maybe someone can answer.

1. On a function class when you return an item
is it possible to return more than one and how is that done?
Currently I am using for one
Avariable = MyFunction()
2. In vb express is it possible to create an application that will allow a
user to write an external class file to add onto it?
What I am thinking is to allow the program to look for a class file, if it
exists, call it. Thus can add one later if needed.

Thanks
Nov 16 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Warex wrote:
1. On a function class when you return an item
is it possible to return more than one and how is that done?
Currently I am using for one
Avariable = MyFunction()
Once way would be to define a structure that holds the different return
values:

Public Structure Results
Dim Result1 As String
Dim Result2 As Integer
Dim Result3 As DateTime
End Structure

Then in your function, you create an instance of this structure and
return that:

Public Function GetValues() As Results
Dim r As Results

r.Result1 = "Some Value"
r.Result2 = 123
r.Result3 = DateTime.Now

Return r
End Function

Another way is to have multiple arguments passed in ByRef then change
their values:

Public Sub GetValues(ByRef R1 As String, ByRef R2 As Integer)
R1 = "Some Value"
R2 = 123
End Sub

You could call it like this:

Dim AString As String
Dim AnInt As Integer

GetValues(AString, AnInt)
>
2. In vb express is it possible to create an application that will allow a
user to write an external class file to add onto it?
What I am thinking is to allow the program to look for a class file, if it
exists, call it. Thus can add one later if needed.
Are you talking about a plug-in type system where 3rd parties can add
functionality to your app?

Yes it can be done, search TheCodeProject.Com for plugin and you should
find some hits.

Basically, you would create an interface that serves as the "contract"
that all plugins must implement, perhaps something like this:

Public Interface IPlugin
Public Function Execute() As Integer
End Interface

You would compile this into an assembly so that plug in writers can use
it.

The plug in writer would then Implement your plugin interface:

Public Class MyPlugInClass
Implements IPlugin

Public Function Execute() As Integer
'do work here
End Function
End Class

This would be compiled into a .dll as well and placed in a folder that
your host app can access.

Your host app would use the classes in System.Reflection to load these
..dll's at runtime and create instances of the IPlugin class from them.
You then call the Execute function to get the plug-in to do its work.

This is a very simple method and doesn't address unloading the plugins
or updating them, but it should give you some things to search on.

Good Luck,

Chris

Nov 16 '06 #2

P: n/a
THanks
"Warex" <Ig************@juno.comwrote in message
news:ey****************@TK2MSFTNGP02.phx.gbl...
Hello,
I have 2 questions maybe someone can answer.

1. On a function class when you return an item
is it possible to return more than one and how is that done?
Currently I am using for one
Avariable = MyFunction()
2. In vb express is it possible to create an application that will allow a
user to write an external class file to add onto it?
What I am thinking is to allow the program to look for a class file, if it
exists, call it. Thus can add one later if needed.

Thanks


Nov 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.