Solved

pass values between vb.net forms

Posted on 2011-02-18
2
383 Views
Last Modified: 2012-05-11
I have a form that calls another form.   I can a variable in form2 before calling the showdialog on the form2 and it uses it in code in form 2.  However I would like to pass a value back to the callingform but that seems to be a no go.  I have enclosed the code to call form2 and the code that is supposed to update a variable on form1 before going back to the code.  Please checkout and let me know why myQty variable is 0 when I return from form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myKeyboard As New frmKeyboard
        Dim mQty As Integer = 0

        myKeyboard.mKeyType = 2
        myKeyboard.mItemDesc = Button1.Text
        myKeyboard.ShowDialog()

        FillListBox(Button1.Text, Button1.Tag, myQty)
    End Sub

Open in new window

Private Sub cmdEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnter.Click
        FrmInspection.myQty = CInt(txtQty.Text)
        Me.Close()

    End Sub

Open in new window

0
Comment
Question by:mgmhicks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Expert Comment

by:omegaomega
ID: 34928779
Hello, mgmhicks,

Where are you declaring and setting FrmInspection?

Cheers,
Randy
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34928791
In FrmInspection, use your "myKeyboard" variable to access the txtQty box on your dialog:
If myKeyboard.ShowDialog() = DialogResult.OK Then
    Me.myQty = CInt(myKeyboard.txtQty.Text)
    FillListBox(Button1.Text, Button1.Tag, Me.myQty)
End If

Open in new window


In myKeyboard, set DialogResult instead of using Close():
Private Sub cmdEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnter.Click
        Me.DialogResult = DialogResult.OK
    End Sub

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question