标签上最后一个表单的错误结果始终为0

时间:2014-02-21 08:05:07

标签: vb.net winforms forms

大家好日子我想在VB.NET中寻求一些关于我的问题的帮助。我有这个程序,如果文本框中的文本等于上一个表单的文本框中的文本,它将为每个正确的答案添加1,但它总是显示零(0)(最后一个表单),而不显示结果我想要。这是我的代码人员,我希望你能事先帮助我解决这个问题。

Imports System.Convert 
Imports System.IO 
Public Class Form3 

Private frm1 As Form1 
Private frm4 As Form4 

Public Sub New1(ByVal callerInstance As Form1) 

    InitializeComponent() 

    ' save the instance of the Me variable passed to this constructor 
    frm1 = callerInstance 
End Sub 

Public Sub New2(ByVal callerInstance As Form4) 

    InitializeComponent() 
    ' save the instance of the Me variable passed to this constructor 
    frm4 = callerInstance 
End Sub 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)       Handles Button1.Click 
    Dim frm1 As Form1 = Form1 
    Dim frm4 As Form4 = Form4 
    frm1 = New Form1 
    frm4 = New Form4 

    'program execution proper 
    Dim lbl3 As Integer = CInt(frm4.Label3.Text) 
    lbl3 = CInt(frm4.Label3.Text) 
    Dim Label22 As New Label 
    If frm1.TextBox2.Text = TextBox1.Text Then 
        lbl3 = CInt(lbl3) + 0 'if(integer.tryparse, lbl3) then lbl3 += 1 
        Dim Label24 As New Label 
        If Not frm1.TextBox4.Text = TextBox2.Text Then 
            lbl3 = CInt(lbl3) + 0 
            Dim Label26 As New Label 
            If Not frm1.TextBox6.Text = TextBox3.Text Then 
                lbl3 = CInt(lbl3) + 0 
                Dim Label28 As New Label 
                If Not frm1.TextBox8.Text = TextBox4.Text Then 
                    lbl3 = CInt(lbl3) + 0 
                    Dim Label30 As New Label 
                    If Not frm1.TextBox10.Text = TextBox5.Text Then 
                        lbl3 = CInt(lbl3) + 0 
                        Dim Label32 As New Label 
                        If Not frm1.TextBox12.Text = TextBox6.Text Then 
                            lbl3 = CInt(lbl3) + 0 
                            Dim Label34 As New Label 
                            If Not frm1.TextBox14.Text = TextBox7.Text Then 
                                lbl3 = CInt(lbl3) + 0 
                                Dim Label36 As New Label 
                                If Not frm1.TextBox16.Text = TextBox8.Text Then 
                                    lbl3 = CInt(lbl3) + 0 
                                    Dim Label38 As New Label 
                                    If Not frm1.TextBox18.Text = TextBox9.Text Then 
                                        lbl3 = CInt(lbl3) + 0 
                                        Dim Label40 As New Label 
                                        If Not frm1.TextBox20.Text = TextBox10.Text Then 
                                            lbl3 = CInt(lbl3) + 0 'frm4.Label3.Text = (frm4.Label3.Text) + 1 
                                            frm4.Show() 
                                            Me.Hide() 
                                        Else 
                                            lbl3 = CInt(lbl3) + 1 
                                            frm4.Show() 
                                            Me.Hide() 
                                        End If 
                                    End If 
                                End If 
                            End If 
                        End If 
                    End If 
                End If 
            End If 
        End If 
    End If 

    If frm4 IsNot Nothing Then 
        frm4.Visible = False 
        frm4.Show(Me) 'Show Second Form 

        Me.Hide() 
    End If 
End Sub 


End Class

2 个答案:

答案 0 :(得分:1)

添加设置代码。

frm4.Label3.Text = lbl3.ToString()

答案 1 :(得分:1)

您向Lbl3添加任何内容的唯一时间是:

If Not frm1.TextBox20.Text = TextBox10.Text Then 
    lbl3 = CInt(lbl3) + 0 'frm4.Label3.Text = (frm4.Label3.Text) + 1 
    frm4.Show() 
    Me.Hide() 
Else 
    lbl3 = CInt(lbl3) + 1 
    frm4.Show() 
    Me.Hide() 
End If 

使用嵌套,只有当所有其他If语句= True时才能达到这一点。

除了所有其他if语句之外,你的结果是lbl3 = CInt(lbl3) + 0(如果这个语句和之前的所有语句都是真的)或者如果其中任何一个是假的,那么所有后续的都是无关紧要的。

如果我理解你的意图,那么你想要的不是:

If frm1.TextBox2.Text = TextBox1.Text Then 
    lbl3 = CInt(lbl3) + 0 'if(integer.tryparse, lbl3) then lbl3 += 1 
    Dim Label24 As New Label 
    If Not frm1.TextBox4.Text = TextBox2.Text Then 
        lbl3 = CInt(lbl3) + 0 

尝试:

If frm1.TextBox2.Text = TextBox1.Text Then lbl3 += 1
If Not frm1.TextBox4.Text = TextBox2.Text Then lbl3 += 1

依旧......

然后要显示它,您需要更新以下代码:

If Not frm1.TextBox20.Text = TextBox10.Text Then 
    lbl3 = CInt(lbl3) + 0 'frm4.Label3.Text = (frm4.Label3.Text) + 1 
    frm4.Label3.Text = CStr(lbl3)
    frm4.Show() 
    Me.Hide() 
Else 
    lbl3 = CInt(lbl3) + 1
    frm4.Label3.Text = CStr(lbl3)
    frm4.Show() 
    Me.Hide() 
End If 

(这与其他一个问题的答案之一非常类似,因此我的上述评论)