Results 1 to 3 of 3

Thread: Call a function from another form

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010

    Call a function from another form

    There are two forms in my project, main.vb and Edit.vb.
    By clicking a button in Main form will open Edit form to update data.
    Once clicking Submit button in Edit form, how to call a function in Main form to display updated data in Main form?
    Is This A Good Question/Topic? 0

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Chelmsford UK

    Re: Call a function from another form

    It's better to open your edit form as a dialog, with your submit button dialogresult set as dialogresult.ok...

    Dim frmEdit as new yourForm
    If frmEdit.ShowDialog = DialogResult.OK Then
      yourOtherForm.Something = frmEdit.someProperty
    End If

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: Call a function from another form

    To expand on what .paul. said, it's almost always better to have communication be a one-way street. By that I don't necessarily mean that data only goes one way but rather that only one party actually performs the communication. You generally have an upstream party and a downstream party, where the former creates the latter. In this case, your main form is the upstream party and it creates the dialogue, which is the downstream party. If at all possible, the downstream party should be completely unaware of the existence of the upstream party. In this case, the dialogue should be completely unaware of the main form. All the dialogue knows is that it has a job to do and it needs to do that job with any input data that it received and then make any results available. It shouldn't care where that input data came from or where the results are going. That way, if you need to, you can use the same dialogue in multiple places in your application. If you tie it directly to the main form then it cannot be reused elsewhere without changes and messy conditional logic. The main form should push any data into the dialogue that is required by the process and, at the end, the main form pulls the results out. That's the upstream party taking responsibility for all the communication.

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