Class Library

G

Guest

We are looking to converting our old vb 6.0 apps to vb.net. In vb6 you
could create a standard set of forms or modules that you could share with
each application. As a result, lets say you opened up one application and
changed something in a module shared throughout multiple apps. The next time
you opened another app the changes would be there and you wouldn't have to
reimport anything. However, this doesn't seem to be the case in .net. It
seems that you have to reimport any changes etc. First, does anyone know how
to do what I am describing in .net?

Second, someone told me a better approach was to use class libraries. Ok,
I'm new to creating class libraries and I am sure there is something I
probably don't know/understand. I started by creating a class library
project. I inserted the following code

public class test1
Dim myConn As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
myconn.connectionstring="somestring"

end class

When I try to say myConn.connectionString="somestring" I get an error that
says declaration expected. What am I doing wrong/don't understand?

Thanks
 
M

Marina

I recommend you buy a book on VB.NET. You are not going to get far without
reading about some of the basic concepts.

To answer your specific question, you can't have code in a class that is not
part of a property or method. You can declare class level variables, but
you can't have anything else just floating around not in a method or
property.
 
K

Ken Halter

Marina said:
I recommend you buy a book on VB.NET. You are not going to get far without
reading about some of the basic concepts.

To answer your specific question, you can't have code in a class that is
not part of a property or method. You can declare class level variables,
but you can't have anything else just floating around not in a method or
property.

Actually, I think the "specific question" was... how to share modules
between apps, most likely using SourceSafe, as I do now in VB6. As long as I
remember to "Get Latest" when I see a shared module in a project, I can use
a single class in dozens of apps.

I need to do some reading too, but topics like this are usually buried very
deep in any books you'd find and that's why newsgroups exist. In fact, I
never did see any docs that show "best practices" when it comes to sharing
modules with SourceSafe. I came up with my own from trial/error.
 
M

Marina

No, he said he was looking at class libraries (which is the way to do it),
and he had a qustion about why there was a compilation error. That was the
question. He just had a brief explanation of what he was trying to do
beforehand.

Most people would not recommend that you share the same physical source file
using VSS. Because then any time that file is changed you have to recompile
all 10 of your applications. As opposed to recompiling just one DLL that
everything else references.
 
K

Ken Halter

Marina said:
No, he said he was looking at class libraries (which is the way to do it),
and he had a qustion about why there was a compilation error. That was the
question. He just had a brief explanation of what he was trying to do
beforehand.

Most people would not recommend that you share the same physical source
file using VSS. Because then any time that file is changed you have to
recompile all 10 of your applications. As opposed to recompiling just one
DLL that everything else references.

Well <g>... In VS6, the choice is yours and there are times when a DLL is
over-kill.... since the second sentence said "In vb6 you could create a
standard set of forms or modules that you could share with each
application." I assumed he was referring to SourceSafe module sharing. I may
be wrong.. In VB5/6, it's also extremely easy (30 seconds or so) to create a
new template that's instantly available to all new apps.... which is another
way to share the same modules across apps. These modules usually start out
small and grow.... which is why, in most cases, you can just use and change
a shared class in a new app, without worrying about rebuilding older apps
that don't require the new functionality.
 
M

m.posseth

Well after carefully rereading the TS`s message , it seems to me that Ken
is right , it seems like the TS is describing exactly how VSS in a
development team works .
Most people would not recommend that you share the same physical source
file using VSS. Because then any time that file is changed you have to
recompile all 10 of your applications. As opposed to recompiling just one
DLL that everything else references.

i do not follow this ,, as you still need to provide the required interface
, so if you do not break the compatibilty what is the need of recompiling
apps ??


regards

Michel Posseth [MCP]





Marina said:
No, he said he was looking at class libraries (which is the way to do it),
and he had a qustion about why there was a compilation error. That was the
question. He just had a brief explanation of what he was trying to do
beforehand.

Most people would not recommend that you share the same physical source
file using VSS. Because then any time that file is changed you have to
recompile all 10 of your applications. As opposed to recompiling just one
DLL that everything else references.
 
G

Guest

I think you can achieve what you want by creating a class library then in
your different application solutions, add the class library project. Then if
you change anything in the class library from one of the applicaitons
solutions, it will be changed in the Class Library project for all of the
Applicaiton solutions. You will, however, be required to rebuild each
applicaiton solution to have the changes take effect.
 
P

Phill. W

John said:
As a result, lets say you opened up one application and changed
something in a module shared throughout multiple apps. The next
time you opened another app the changes would be there and you
wouldn't have to reimport anything.

Ah; I remember it well.

The problem here is the way that files get added to your Project.
By default, VB.Net takes a /local copy/ of your source file when
you add it - you have to "persuade" it to simply "use" the file
wherever you left it.

When adding files to a Project, look closely at the "Add" button -
it has a dropdown list attached to it. Select the "Link File" option
from this list and VB.Net will simply [re-]use the file in its original
(shared) location rather than stealing [yet] a[nother] copy of it.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top