Question Transfering Data Between multiple forms

Codeman0013

New member
Joined
Dec 31, 2008
Messages
3
Programming Experience
Beginner
All,

I have 10 forms in my application. Each form server a purpose. Its basically a shopping cart application. What i'm wanting is to keep track of everything a user does on every form until they get to the summary form and have it display. What would be the best way to take it. For example on the main form i have txtid chkys chkno i need to keep track of what is in the text and the check and have that display on the 10th summary form as well as all the other clicks in between. Never done this before but i'm more of a form guy then all around code and was asked to try this for a project any suggestions would be greatly appreciated.
 
This is a question that gets asked a lot but it's because people want to think of forms as being different to other objects when they're not. Form's are objects just like any other and, as such, you pass data between them just as you do any other objects. To get data into an object you either set a property or call a method and pass an argument. To get data out of an object you get a property or call a method and get the return value. This goes for forms just as it does any other objects.

So, in each form that needs to receive data, you need to declare properties and or methods for the purpose. The calling form that creates that form can then set those properties and/or call those methods to get data in. Here's a simple example:
VB.NET:
Using dialogue As New Form2
    'Pass data into the dialogue.
    dialogue.SomeProperty = someValue
    dialogue.SomeMethod(someOtherValue)

    'Display the dialogue.
    If dialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then
        'Get data out of the dialogue.
        someValue = dialogue.SomeOtherProperty
        someOtherValue = dialogue.SomeOtherMethod()
    End If
End Using
 
So in this case i could pass the following..


Using dialogue As New SummaryForm
'Pass data into the dialogue.
dialogue.stuff= txtid.text


'Display the dialogue.
If dialogue.ShowDialog() = Windows.Forms.DialogResult.OK Then
'Get data out of the dialogue.
txtid.text= dialogue.SomeOtherProperty
someOtherValue = dialogue.SomeOtherMethod()
End If
End Using


Like i said i'm new and still learning and very noobish in this
 
That's correct. It's up to you to declare the Stuff property in the SummaryForm class, plus any other properties and/or methods that are required. If the SummaryForm class ALWAYS needs this data then you can also declare a constructor, i.e Sub New, with one or more parameters. That way it's not possible to create an instance without passing in the required data.
 
Ok, I guess I'm a little confused still. I have never done this, so please bear with me... you say i can do a constructor..

Basically this is a shopping cart where each time it will be different.
How do it tell it to remember what was selected on each one? I guess my question is, how do it tell it that certain things need to be in there?

I.e they request on one form a secure id, but thats all they do.
They would have info from the first form (mainform), then the 2nd form (authorizing manager), then the remoteaccess form, and then finally print that all on the summary.

I just dont know much about constructors.
 
Last edited by a moderator:
Back
Top