|
-
Sep 17th, 2007, 11:50 AM
#1
Thread Starter
Junior Member
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
-
Sep 17th, 2007, 11:53 AM
#2
Re: Forms Talking to each other?
Try the ShowDialog method
e.g.
That is a blocking call
-
Sep 17th, 2007, 11:54 AM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Sep 17th, 2007, 11:56 AM
#4
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.
-
Sep 17th, 2007, 12:23 PM
#5
Thread Starter
Junior Member
Re: Forms Talking to each other?
Thank you all for your help. I used showdialog() and that's exactly what I was looking for.
-
Sep 17th, 2007, 12:27 PM
#6
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.
-
Sep 17th, 2007, 11:56 PM
#7
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|