Solved

pass values between vb.net forms

Posted on 2011-02-18
2
369 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
2 Comments
 
LVL 12

Expert Comment

by:omegaomega
ID: 34928779
Hello, mgmhicks,

Where are you declaring and setting FrmInspection?

Cheers,
Randy
0
 
LVL 85

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 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