Click here to Skip to main content
15,896,469 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionA MCAD or MCPD question. Pin
sl701020-Apr-10 6:10
sl701020-Apr-10 6:10 
AnswerRe: A MCAD or MCPD question. Pin
Not Active20-Apr-10 7:14
mentorNot Active20-Apr-10 7:14 
QuestionHelp with structures! Pin
bassmaster_general20-Apr-10 5:19
bassmaster_general20-Apr-10 5:19 
AnswerRe: Help with structures! Pin
Not Active20-Apr-10 5:44
mentorNot Active20-Apr-10 5:44 
AnswerRe: Help with structures! Pin
DaveyM6920-Apr-10 5:44
professionalDaveyM6920-Apr-10 5:44 
AnswerRe: Help with structures! Pin
bassmaster_general20-Apr-10 6:04
bassmaster_general20-Apr-10 6:04 
GeneralRe: Help with structures! Pin
Luc Pattyn20-Apr-10 6:35
sitebuilderLuc Pattyn20-Apr-10 6:35 
GeneralRe: Help with structures! Pin
Gregory Gadow21-Apr-10 4:46
Gregory Gadow21-Apr-10 4:46 
A few suggestions:

Generally speaking, classes should be used rather than structures. As reference types, classes use memory more efficiently, which is important if objects are going to be persisted for any length of time.

Putting your data class/structure outside the class will make it accessable to other parts of your code. If you flag it as Friend, it will be available in your module but not be exposed to users of your library.

Using the Property syntax will self-document that a variable is actually a property, allow you to have different scopes for getting and setting the property and do pre- and post-processing when you set the values such as raise events, change control visibility and so on. Even if you do not need this functionality now, there is no harm in building your code to be easily extensible.

You can avoid several problems by using a strongly typed enumerable like List(Of T) rather than generic enumerables like ArrayList. Another advantage is that the enumerable can be exposed as a read-only property, which lets you use its Add method instead of having to write your own.

Note also that MyClass is a keyword in VB.Net. Poke tongue | ;-P

I would have written something like this:
VB.NET
Friend Class PatientData

    Private _myDate As Date
    Private _myDouble1 As Double
    Private _myDouble2 As Double
    Private _myDouble3 As Double

    Public Property MyDate() As Date
        Get
            Return _myDate
        End Get
        Set(ByVal value As Date)
            _myDate = value
        End Set
    End Property

    'And so on with the other properties

    Public Sub New(ByVal VisitDate As Date, ByVal BMI As Double, _
    ByVal Height As Double, ByVal Weight As Double)
        _myDate = VisitDate
        _myDouble1 = BMI
        _myDouble2 = Height
        _myDouble3 = Weight
    End Sub

End Class

Public Class OtherClass

    Private _visitData As List(Of PatientData)

    Friend ReadOnly Property VisitData() As List(Of PatientData)
        Get
            If _visitData Is Nothing Then _visitData = New List(Of PatientData)
            Return _visitData
        End Get
    End Property

End Class


The Friend scope on PatientData means that the class can be used within your project but not outside it. That the properties of PatientData are Public makes no difference, as the more restrictive Friend will hide the whole class. You might want to set the class to Public but code the properties to Friend Set: the class will be available with read-only properties outside of your project but have read and write properties within. You could also flag the constructor with Friend, which will let you use existing instances of PatientData outside of your project but not create new ones.

Now, you can add a new visit to your list like this:
VB.NET
OtherClassInstance.VisitData.Add(New PatientData(visitDate, bmi, height, weight))

QuestionSwitch colums and rows in vb.net datagrid Pin
Peter Leipzig19-Apr-10 16:18
Peter Leipzig19-Apr-10 16:18 
AnswerRe: Switch colums and rows in vb.net datagrid Pin
Dr.Walt Fair, PE19-Apr-10 16:45
professionalDr.Walt Fair, PE19-Apr-10 16:45 
AnswerRe: Switch colums and rows in vb.net datagrid Pin
Ashfield19-Apr-10 22:34
Ashfield19-Apr-10 22:34 
GeneralRe: Switch colums and rows in vb.net datagrid Pin
Peter Leipzig20-Apr-10 3:39
Peter Leipzig20-Apr-10 3:39 
GeneralRe: Switch colums and rows in vb.net datagrid Pin
gmhanna20-Apr-10 5:25
gmhanna20-Apr-10 5:25 
GeneralRe: Switch colums and rows in vb.net datagrid Pin
Ashfield20-Apr-10 8:45
Ashfield20-Apr-10 8:45 
QuestionOLE MS-Access Database - Syntax error in FROM clause Pin
gmhanna19-Apr-10 14:33
gmhanna19-Apr-10 14:33 
AnswerRe: OLE MS-Access Database - Syntax error in FROM clause Pin
Eddy Vluggen20-Apr-10 9:13
professionalEddy Vluggen20-Apr-10 9:13 
QuestionMessage Removed Pin
19-Apr-10 3:56
professionalN_tro_P19-Apr-10 3:56 
AnswerRe: IntelliTrace not what I thought Pin
Dave Kreskowiak19-Apr-10 4:06
mveDave Kreskowiak19-Apr-10 4:06 
GeneralMessage Removed Pin
19-Apr-10 4:12
professionalN_tro_P19-Apr-10 4:12 
GeneralRe: IntelliTrace not what I thought Pin
Dave Kreskowiak19-Apr-10 10:33
mveDave Kreskowiak19-Apr-10 10:33 
Questiondifference between abstract class and interface Pin
Balaji_Reddy19-Apr-10 0:37
Balaji_Reddy19-Apr-10 0:37 
AnswerRe: difference between abstract class and interface Pin
Eddy Vluggen19-Apr-10 2:45
professionalEddy Vluggen19-Apr-10 2:45 
GeneralRe: difference between abstract class and interface Pin
Balaji_Reddy19-Apr-10 4:49
Balaji_Reddy19-Apr-10 4:49 
GeneralRe: difference between abstract class and interface Pin
Richard MacCutchan19-Apr-10 5:01
mveRichard MacCutchan19-Apr-10 5:01 
GeneralRe: difference between abstract class and interface Pin
Eddy Vluggen19-Apr-10 5:32
professionalEddy Vluggen19-Apr-10 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.