Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Load form count

Load form count

Scheduled Pinned Locked Moved Visual Basic
debugginghelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tatchung
    wrote on last edited by
    #1

    Hello, How could I trace which form was previously loaded within my application? Sorry but I'm a bit lost on how to explain this let alone put this into code. Here's the story, I have an application which loads to form1. From form1 I can load to form2. Then from form2 I can load back to form1 taking a couple of variables to display in my datagrid in form1. So I was looking at a broken code like this

    If previous form = form1 then
    execute cmd1
    else if previous form = form3 then
    execute cmd3
    etc....

    Any help would be greatly appreciated. Thanks in advance :-D

    Aim small, miss small

    J D 2 Replies Last reply
    0
    • T tatchung

      Hello, How could I trace which form was previously loaded within my application? Sorry but I'm a bit lost on how to explain this let alone put this into code. Here's the story, I have an application which loads to form1. From form1 I can load to form2. Then from form2 I can load back to form1 taking a couple of variables to display in my datagrid in form1. So I was looking at a broken code like this

      If previous form = form1 then
      execute cmd1
      else if previous form = form3 then
      execute cmd3
      etc....

      Any help would be greatly appreciated. Thanks in advance :-D

      Aim small, miss small

      J Offline
      J Offline
      Jon_Boy
      wrote on last edited by
      #2

      Implement a shared variable on the form and increase it in the constructor and decrement when destroying the form. Something like,

      class whatever
      Implements IDisposable
      Private mblnDisposed As Boolean = False

      Public Shared iCount As Integer = 0
      
      Sub New()
          iCount += 1
      End Sub
      

      'Dispose, etc down here
      end class

      Any suggestions, ideas, or 'constructive criticism' are always welcome.

      1 Reply Last reply
      0
      • T tatchung

        Hello, How could I trace which form was previously loaded within my application? Sorry but I'm a bit lost on how to explain this let alone put this into code. Here's the story, I have an application which loads to form1. From form1 I can load to form2. Then from form2 I can load back to form1 taking a couple of variables to display in my datagrid in form1. So I was looking at a broken code like this

        If previous form = form1 then
        execute cmd1
        else if previous form = form3 then
        execute cmd3
        etc....

        Any help would be greatly appreciated. Thanks in advance :-D

        Aim small, miss small

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You're treating forms like a trail of breadcumbs. This is not the case. Forms create instances of other forms in a hierarchical fashion. If, say, Form1 creates an instance of Form2 to get some data, Form1 should call Form2's .ShowDialog method, not Show. This way, Form1 will know exactly when Form2 is closed and is free to grab any data it needs from it. Form2 should not care at all which form created it, nor should it care about what data it needs to pass back to the form that called it. It's not Form2's job to do any of this. Form2's job is just to get data from the user or whever, not to pass it around. Form1 should know which methods it needs to call on Form2, not the other way around.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        T 1 Reply Last reply
        0
        • D Dave Kreskowiak

          You're treating forms like a trail of breadcumbs. This is not the case. Forms create instances of other forms in a hierarchical fashion. If, say, Form1 creates an instance of Form2 to get some data, Form1 should call Form2's .ShowDialog method, not Show. This way, Form1 will know exactly when Form2 is closed and is free to grab any data it needs from it. Form2 should not care at all which form created it, nor should it care about what data it needs to pass back to the form that called it. It's not Form2's job to do any of this. Form2's job is just to get data from the user or whever, not to pass it around. Form1 should know which methods it needs to call on Form2, not the other way around.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          T Offline
          T Offline
          tatchung
          wrote on last edited by
          #4

          Dave Kreskowiak wrote:

          You're treating forms like a trail of breadcumbs.

          :laugh: yeah I guess you're right.

          Dave Kreskowiak wrote:

          Form1 should call Form2's .ShowDialog method, not Show

          got it! Form1 calls upon data that form2 generates not form2 passes the data back to form1. Many thanks again for the tip! :-D

          Aim small, miss small

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups