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

Basic How To Question: Class Library or Windows Control Library

P: n/a
I have several applications which mine web sites for personal information
which they publish. They publish the info in one form, I transform the info
into Excel spreadsheets.

So all these programs pick up name, telephone number, age, sex, etc.. And
as they pick up the information they display it in text boxes. The text
boxes are display only, and the info is displayed only for debugging
purposes.

Right now I have a lot of duplicate code in these several applications.
What I'd like to do is create one something, a class library or a user
control, which eliminates all of the duplicate code. So this "something" as
I envision it will be a collection of labels and textboxes (tbxName, tbxTel,
tbxSex, etc.) and a class with corresponding fields (Name, Telephone, Sex,
etc.). The something should also contain related subroutines such as the
code which opens, writes, and closes the Excel spreadsheet.

I wasn't sure if I needed a user control or a class library, but I have
opted for the user control because I want to be able to plonk down the
collection of labels and text boxes during the design of the consuming
applications.

I am now at the point where I have a bunch of labels and text boxes defined
on my "UserControl1.vb[Design]* tab. And now I am trying to define a class
of corresponding fields. So following my "Windows Form Designer generated
code" I have ...

Public Class Person

Private mpName As String

Public Property Name() As String

Get

Return mpName

End Get

Set(ByVal Value As String)

mpName = Value

UserControl1.tbxName = Value '<<<<< this is where I have a problem

End Set

End Property

....

If it matters, note that this Person class is nested within the Public Class
UserControl1. I didn't know classes can be nested but I guess I do now.

I suspect that I am really not going about this in the right way at all.
But, if I am, then my problem is that I do not know how to specify the
controls which correspond to my fields. You'll see above that I tried
UserControl1.tbxName which I knew was wrong, but it at least conveys what I
am trying to do. I had high hopes for me.tbxName but that did not work
either.

So ... any advice or pointers you can share with me will be greatly
appreciated.

Thanks, Bob
Feb 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi eBob

You could consider creating both a Class Library (which contains all your
business logic and properties) and a UserControl (which contains all UI
elements.) and then link both of them together. There is of course the
option of nesting everything within one class, but it's not very good coding
practice in my opinion, especially considering that the Reusability
requirement in your project is high.

As for the confusion about whether to use a Class Library or UserControl,

By Definition :
- A Class Library template is used to quickly create reusable classes and
components that can be shared with other projects.

- The UserControl provides an empty control that can be used to create other
controls, and gives you the ability to create controls that can be used in
multiple places within an application.

So, to summarize, the Class library should contain all the logic by which
you load data, it will have properties and methods, while your UserControl
should handle the displaying of the data in the TextBoxes.
UserControl1.tbxName = Value '<<<<< this is where I have a problem
I fail to understand what exactly you are trying to do by this statement.
You are equating a Control (texbox) with a string value, which won't work.
I'm assuming that you want to change the text of the Textbox here.

if tbxName is the name of a TextBox, then to change it's text, just do :
tbxName.Text = MyClass.PropertyName
where MyClass is the name of your ClassLibrary and PropertyName is the name
of the relevant property.

I would recommend that you check up on some tutorials on the web or MSDN,
which will clear these concepts.

Lemme know if you need more info,

Regards,

Cerebrus.

"eBob.com" <fa******@totallybogus.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl... I have several applications which mine web sites for personal information
which they publish. They publish the info in one form, I transform the info into Excel spreadsheets.

So all these programs pick up name, telephone number, age, sex, etc.. And
as they pick up the information they display it in text boxes. The text
boxes are display only, and the info is displayed only for debugging
purposes.

Right now I have a lot of duplicate code in these several applications.
What I'd like to do is create one something, a class library or a user
control, which eliminates all of the duplicate code. So this "something" as I envision it will be a collection of labels and textboxes (tbxName, tbxTel, tbxSex, etc.) and a class with corresponding fields (Name, Telephone, Sex,
etc.). The something should also contain related subroutines such as the
code which opens, writes, and closes the Excel spreadsheet.

I wasn't sure if I needed a user control or a class library, but I have
opted for the user control because I want to be able to plonk down the
collection of labels and text boxes during the design of the consuming
applications.

I am now at the point where I have a bunch of labels and text boxes defined on my "UserControl1.vb[Design]* tab. And now I am trying to define a class of corresponding fields. So following my "Windows Form Designer generated
code" I have ...

Public Class Person

Private mpName As String

Public Property Name() As String

Get

Return mpName

End Get

Set(ByVal Value As String)

mpName = Value

UserControl1.tbxName = Value '<<<<< this is where I have a problem

End Set

End Property

...

If it matters, note that this Person class is nested within the Public Class UserControl1. I didn't know classes can be nested but I guess I do now.

I suspect that I am really not going about this in the right way at all.
But, if I am, then my problem is that I do not know how to specify the
controls which correspond to my fields. You'll see above that I tried
UserControl1.tbxName which I knew was wrong, but it at least conveys what I am trying to do. I had high hopes for me.tbxName but that did not work
either.

So ... any advice or pointers you can share with me will be greatly
appreciated.

Thanks, Bob

Feb 20 '06 #2

P: n/a
Thank you Cerebrus. I make that mistake so often (i.e. typing tbxWhatEver =
SomeString instead of tbx.WhatEver.Text = SomeString).

I am making progress now.

Thanks again, Bob

"Cerebrus99" <zo*****@sify.com> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
Hi eBob

You could consider creating both a Class Library (which contains all your
business logic and properties) and a UserControl (which contains all UI
elements.) and then link both of them together. There is of course the
option of nesting everything within one class, but it's not very good
coding
practice in my opinion, especially considering that the Reusability
requirement in your project is high.

As for the confusion about whether to use a Class Library or UserControl,

By Definition :
- A Class Library template is used to quickly create reusable classes and
components that can be shared with other projects.

- The UserControl provides an empty control that can be used to create
other
controls, and gives you the ability to create controls that can be used in
multiple places within an application.

So, to summarize, the Class library should contain all the logic by which
you load data, it will have properties and methods, while your UserControl
should handle the displaying of the data in the TextBoxes.
UserControl1.tbxName = Value '<<<<< this is where I have a problem


I fail to understand what exactly you are trying to do by this statement.
You are equating a Control (texbox) with a string value, which won't work.
I'm assuming that you want to change the text of the Textbox here.

if tbxName is the name of a TextBox, then to change it's text, just do :
tbxName.Text = MyClass.PropertyName
where MyClass is the name of your ClassLibrary and PropertyName is the
name
of the relevant property.

I would recommend that you check up on some tutorials on the web or MSDN,
which will clear these concepts.

Lemme know if you need more info,

Regards,

Cerebrus.

"eBob.com" <fa******@totallybogus.com> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
I have several applications which mine web sites for personal information
which they publish. They publish the info in one form, I transform the

info
into Excel spreadsheets.

So all these programs pick up name, telephone number, age, sex, etc..
And
as they pick up the information they display it in text boxes. The text
boxes are display only, and the info is displayed only for debugging
purposes.

Right now I have a lot of duplicate code in these several applications.
What I'd like to do is create one something, a class library or a user
control, which eliminates all of the duplicate code. So this "something"

as
I envision it will be a collection of labels and textboxes (tbxName,

tbxTel,
tbxSex, etc.) and a class with corresponding fields (Name, Telephone,
Sex,
etc.). The something should also contain related subroutines such as the
code which opens, writes, and closes the Excel spreadsheet.

I wasn't sure if I needed a user control or a class library, but I have
opted for the user control because I want to be able to plonk down the
collection of labels and text boxes during the design of the consuming
applications.

I am now at the point where I have a bunch of labels and text boxes

defined
on my "UserControl1.vb[Design]* tab. And now I am trying to define a

class
of corresponding fields. So following my "Windows Form Designer
generated
code" I have ...

Public Class Person

Private mpName As String

Public Property Name() As String

Get

Return mpName

End Get

Set(ByVal Value As String)

mpName = Value

UserControl1.tbxName = Value '<<<<< this is where I have a problem

End Set

End Property

...

If it matters, note that this Person class is nested within the Public

Class
UserControl1. I didn't know classes can be nested but I guess I do now.

I suspect that I am really not going about this in the right way at all.
But, if I am, then my problem is that I do not know how to specify the
controls which correspond to my fields. You'll see above that I tried
UserControl1.tbxName which I knew was wrong, but it at least conveys what

I
am trying to do. I had high hopes for me.tbxName but that did not work
either.

So ... any advice or pointers you can share with me will be greatly
appreciated.

Thanks, Bob


Feb 20 '06 #3

P: n/a
> I am making progress now.

Thanks again, Bob

Good to hear that ! :-)

Regards,

Cerebrus.
Feb 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.