VB.Net无法获取第一个表单上的值

时间:2014-02-14 01:59:23

标签: vb.net winforms forms

我想请求您对我的项目的帮助,因为您可以看到它有一个调用者实例,另一种形式也有它并且它正在工作(没有数学运算)但是在这个form3上我需要一个在frm4.label上+1它不起作用。 (我把它命名为Public Sub New1)错误1'Public Sub New()的参数太多(注意:我在前一个表单上有另一个调用实例,它是form2,名为Public SubNew()),当它运行而不是获取正确的结果标签始终显示0的文本 请帮助我提前感谢所有人的快乐编码:)

Public Class Form3
Private frm3 As Form3
Private frm1 As Form1
Private frm4 As Form4

Public Sub New1(ByVal Name As String, ByVal Bread As String, ByVal Cheese As String, ByVal Condiments As String, ByVal Meat As String, ByVal Cost As Decimal, ByVal Quantity As Decimal, ByVal callerInstance As Form1)

    ' Call required if you add your constructor manually
    InitializeComponent()

    ' save the instance of the Me variable passed to this constructor
    frm1 = callerInstance
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    frm1 = New Form1(Me)
    frm4 = New Form4()


    If frm4 Is Nothing Then
        frm4 = New Form4
        AddHandler frm4.FormClosed, AddressOf Me.Form4HasBeenClosed

        Dim i As Integer = 0
        i = frm4.Label3.Text
        If TextBox1.Text = frm1.TextBox2.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1

        ElseIf TextBox2.Text = frm1.TextBox4.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox3.Text = frm1.TextBox6.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox4.Text = frm1.TextBox8.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox5.Text = frm1.TextBox10.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox6.Text = frm1.TextBox12.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox7.Text = frm1.TextBox14.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox8.Text = frm1.TextBox16.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox9.Text = frm1.TextBox18.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
        ElseIf TextBox10.Text = frm1.TextBox20.Text Then
            i = +1 'frm4.Label3.Text = (frm4.Label3.Text) + 1

            frm4.Label3.Text = i.ToString()

            frm4.Show()


        Else
            i += 0
            frm4.Show()
        End If
    End If

    If frm4 IsNot Nothing Then
        frm4.Show(Me) 'Show Second Form  
        Me.Hide()
    End If

End Sub
Sub Form4HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
    frm4 = Nothing
End Sub

结束班

1 个答案:

答案 0 :(得分:0)

根据评论,这听起来像错误就在这一行

frm1 = new Form1(Me)

如果是这种情况,则意味着Sub New上没有Form1方法接受Form3类型的参数。要解决此问题,您需要添加一个

Public Class Form1
  ...
  Public Sub New(ByVal frm3 As Form3)

  End Sub
End Class