Results 1 to 7 of 7

Thread: Forms Talking to each other?

  1. #1

    Thread Starter
    Junior Member w8taminute's Avatar
    Join Date
    Aug 2006
    Posts
    24

    Forms Talking to each other?

    Hello everyone,

    I am trying to get one of my forms (frm1) to show another form (frm2) and then wait until the a button is clicked in frm2 to continue with the following code in frm1.
    Here is an example:


    Dim var1 as Integer
    Dim frm2 As New frm2
    frm2.Show()
    var1 = var2

    I want to pass the value of var2 to var1 when I click a button. var2 comes from frm2. What is happens instead is,frm1 shows frm2 and continues on to the next line (var1=var2). Can anyone help?
    Reply With Quote

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Forms Talking to each other?

    Try the ShowDialog method
    e.g.
    Code:
    frm2.ShowDialog
    That is a blocking call

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Forms Talking to each other?

    Use ShowDialog so it stops processing on the first form until the second is closed.
    Code:
    Dim var1 as Integer
    Dim frm2 As New frm2
    frm2.ShowDialog()
    var1 = var2
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Forms Talking to each other?

    Remove var1 = var2 from the Form Load.

    Presuming both are declared on Form1, make them Public variables. Then in your button on Form2, just do
    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Form1.var1 = Form1.var2
        End Sub
    If var2 is declared on Form2, then remove the Form1 prefix from var2.

  5. #5

    Thread Starter
    Junior Member w8taminute's Avatar
    Join Date
    Aug 2006
    Posts
    24

    Re: Forms Talking to each other?

    Thank you all for your help. I used showdialog() and that's exactly what I was looking for.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Forms Talking to each other?

    If you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.

    Thank you.

  7. #7
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    Re: Forms Talking to each other?

    Hi,

    How to pass TextBox values from one Form to Another
    http://yulyos4vbnet.spaces.live.com/...2024!169.entry

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