Page 2 of 2 FirstFirst 12
Results 41 to 48 of 48

Thread: The Definitive "Passing Data Between Forms"

  1. #41
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: The Definitive "Passing Data Between Forms"

    Quote Originally Posted by Pradeep1210 View Post
    Though strings are reference types in .NET, they don't quite behave as such.
    Instead they behave more like value types rather than reference types. They are mutable. One string can't change the contents of another string even if they are pointing to the same memory location. As soon as you try to do that, .NET will create a new memory location and make it point there.
    you are correct. To be honest, I am not sure why I said that originally (was 2 years ago). Although one thing to note is strings are actually immutable, not mutable.

  2. #42
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: The Definitive "Passing Data Between Forms"

    When adding an overloaded new constructor to a form it will never show up in the Project properties Startup form ComboBox. It should not matter but thought it prudent to mention. If you want it to show up then add a default new constructor along with the overloaded new constructor. For anyone who wants to try this out download the attachment, which has two, projects and load them. No need to build either project but instead look at the Startup ComboBox and note one form is missing in both. In the temp project note there is no form1 but it shows up in the Startup form ComboBox which happened when Form1 was removed then the form with an overloaded new constructor was added. Any ways I thought this was interesting as it happened to a fellow developer who asked me what was going on.

    To me this is a non-issue unless you are not sure what the heck is going on.
    Attached Files Attached Files

  3. #43
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: The Definitive "Passing Data Between Forms"

    There's a reason for that... When the application starts, it creates an instance of the form. As such, there isn't a way to pass parameters to the constructor of the form ... after all, how would it know what to send to the form? That's why you need to have a parameterless constructor of the form. So the IDE removes any form that doesn't have a parameterless constructor.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #44
    Member
    Join Date
    Sep 2011
    Posts
    39

    Re: The Definitive "Passing Data Between Forms"

    I'm still fairly new at VB (using VB .NET for the moment) and I have a question that I didn't see addressed in this thread.

    I'm trying to pass a bunch of variables from one form to another. In other languages I have used, I've been able to build a structure (although I'm not sure how to do that in VB yet). For single variables I have been using the code that has been mentioned in this thread:

    Private ReadOnly Property _PassMetFile1() As String
    Get
    Return firstmet.Text
    End Get
    End Property

    and

    Friend WriteOnly Property _ReceiveMetFile1() As String
    Set(ByVal value As String)
    metfile1 = value
    End Set
    End Property


    I am not trying to pass about 25 fields from one form to another and I obviously don't want to go through those statements all 25 times.

    Is there a way to build all 25 fields into one variable and pass it from one form to another?

    Thanks

  5. #45
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: The Definitive "Passing Data Between Forms"

    you can pass it as a List(Of String) ... you can use a custom class... or a structure... or an array even....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #46

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: The Definitive "Passing Data Between Forms"

    You can certainly create a class or structure and pass that. You would be changing the property to take a member of that class or structure type rather than a string, but it would otherwise work the same. If all the items you want to pass are strings, I would agree with TG that you should just pass a List(of String).

    In any case, you may have just as much trouble populating a structure as you would passing 25 different values individually. Of course, there would be more code involved adding those 25 properties onto the form, but once you had done that, passing the values would be easier than filling a structure then passing the structure....unless your code is such that the structure can be filled for other reasons such that you get more benefit from having the structure than just to simplify passing it around.
    My usual boring signature: Nothing

  7. #47
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: The Definitive "Passing Data Between Forms"

    Of course that also asks the question why so much needs to be passed over? Surely there's a better way ...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #48
    Member
    Join Date
    Sep 2011
    Posts
    39

    Re: The Definitive "Passing Data Between Forms"

    Thanks for the all the suggestions. I'm going to try to use the List(Of String) approach and see how that works. If it fails, I'll just pass everything over individually.

    The reason that I need to pass a bunch of data is that I am creating an environment to run a program with a lot of variables. Generally the program will be run with default values and I won't need to the user to change them, but they need the ability to modify it if they want.

    So, I made a seperate page to modify the default values. If they change them, then when they close that page, VB will use those new values instead of the default ones.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width