Home All Groups Group Topic Archive Search About

Passing Vb equivilent of "structs" between forms

Author
31 Mar 2006 9:51 AM
Chris Strug
Hi,

I'm working with VB 2005.net and have managed to get my head around passing
values between forms by creating properties of the relevant form classes.

However, say that I have a number of values which I wish to exchange (for
example, an employee record, name, position, etc). At the minute I'm using a
seperate property to for each "field".

I was wondering, is there a way to collate all the fields into one "object"
and use that as a property? I'm reminded of a "struct" from my C days and
was wondering if VB provided anything similar?

Any and all advice, tips, links and abuse are gratefully received.

Thanks

Chris,

Author
31 Mar 2006 10:22 AM
Martin
Structure / End Structure

Show quoteHide quote
"Chris Strug" <solace1***@hotmail.com> wrote in message
news:%23CVX5iKVGHA.4956@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I'm working with VB 2005.net and have managed to get my head around
> passing values between forms by creating properties of the relevant form
> classes.
>
> However, say that I have a number of values which I wish to exchange (for
> example, an employee record, name, position, etc). At the minute I'm using
> a seperate property to for each "field".
>
> I was wondering, is there a way to collate all the fields into one
> "object" and use that as a property? I'm reminded of a "struct" from my C
> days and was wondering if VB provided anything similar?
>
> Any and all advice, tips, links and abuse are gratefully received.
>
> Thanks
>
> Chris,
>
Author
31 Mar 2006 10:28 AM
Chris Strug
"Martin" <x@y.com> wrote in message
news:uOkc%23zKVGHA.776@TK2MSFTNGP09.phx.gbl...
> Structure / End Structure
>

Martin,

Thank you and apologies for my laziness / myopia when it comes to the help
files.

Thanks

CS
Author
31 Mar 2006 11:00 AM
Martin
You're forgiven, the helpfiles of VS2005 are totally useless ;-)

Show quoteHide quote
"Chris Strug" <solace1***@hotmail.com> wrote in message
news:O0D1d3KVGHA.4960@TK2MSFTNGP12.phx.gbl...
> "Martin" <x@y.com> wrote in message
> news:uOkc%23zKVGHA.776@TK2MSFTNGP09.phx.gbl...
>> Structure / End Structure
>>
>
> Martin,
>
> Thank you and apologies for my laziness / myopia when it comes to the help
> files.
>
> Thanks
>
> CS
>
Author
31 Mar 2006 11:46 AM
Phill W.
"Chris Strug" <solace1***@hotmail.com> wrote in message
news:%23CVX5iKVGHA.4956@TK2MSFTNGP09.phx.gbl...

> However, say that I have a number of values which I wish to exchange (for
> example, an employee record, name, position, etc). At the minute I'm using
> a seperate property to for each "field".

Properties of what?  Each Form?  Or a Class, each instance of which
represents an Employee?

> I was wondering, is there a way to collate all the fields into one
> "object" and use that as a property?

You could go with a Structure (the direct equivalent of struct) but,
personally, I'd jump straight in with a Class.  Maybe something like this
(only with [lots] more Properties):

Class Employee
    ' ? Inherits BaseClassForAnyPerson

    Private m_EmpNumber As String = Nothing

    Public ReadOnly Property EmpNumber() As String
        . . .
    End Property

    Public Sub LoadFrom( ByVal source As ... )
        m_EmpNumber = source.Something
        . . .
    End Sub

    Public Sub SaveTo( ByVal source As ... )
        . . .
    End Sub

    Public Sub New( ByVal source As ... )
        Me.LoadFrom( source )
    End Sub

End Class

HTH,
    Phill  W.