0

我正在创建一个程序,如果我单击它,button5(summary)它不会在我第一次单击之前显示摘要报告button1(compute)。我该怎么做呢?

相关代码:

Private Sub Button5_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Button5.Click

   If Not IsNumeric(TextBox6.Text) Or _
       Not IsNumeric(TextBox7.Text) Or _
       Not IsNumeric(TextBox8.Text) Or _
       Not IsNumeric(TextBox9.Text) Then
     MessageBox.Show("Invalid Input", "Warning", _
       MessageBoxButtons.OK, MessageBoxIcon.Warning)
   ElseIf 99 >= TextBox6.Text Or _
       99 >= TextBox7.Text Or _
       99 >= TextBox8.Text Or _
       99 >= TextBox9.Text Then
     MessageBox.Show("Invalid Amount", "Warning", _
       MessageBoxButtons.OK, MessageBoxIcon.Warning)
   Else
     Form5.Show()
     Me.Hide()
     Form5.Label3.Text = TextBox1.Text
     Form5.Label5.Text = TextBox2.Text
     Form5.Label7.Text = TextBox3.Text
     Form5.Label9.Text = ComboBox1.Text
     Form5.Label11.Text = TextBox4.Text
     Form5.Label13.Text = ComboBox2.Text
     Form5.Label15.Text = Label27.Text
     Form5.Label22.Text = Label14.Text
     Form5.Label17.Text = Label22.Text
     Form5.Label19.Text = Label25.Text
   End If
End Sub
4

1 回答 1

0

尝试在您Button1_Click()的处理程序开始时调用您的处理Button5_Click程序:

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

    Button1_Click() 'Call the handler at the start of your subroutine

    If Not IsNumeric(TextBox6.Text) Or Not IsNumeric(TextBox7.Text) Or Not IsNumeric(TextBox8.Text) Or Not IsNumeric(TextBox9.Text) Then
        MessageBox.Show("Invalid Input", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

    ElseIf 99 >= TextBox6.Text Or 99 >= TextBox7.Text Or 99 >= TextBox8.Text Or 99 >= TextBox9.Text Then
        MessageBox.Show("Invalid Amount", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)



    Else
        Form5.Show()
        Me.Hide()
        Form5.Label3.Text = TextBox1.Text
        Form5.Label5.Text = TextBox2.Text
        Form5.Label7.Text = TextBox3.Text
        Form5.Label9.Text = ComboBox1.Text
        Form5.Label11.Text = TextBox4.Text
        Form5.Label13.Text = ComboBox2.Text
        Form5.Label15.Text = Label27.Text
        Form5.Label22.Text = Label14.Text
        Form5.Label17.Text = Label22.Text
        Form5.Label19.Text = Label25.Text

    End If
End Sub

假设Button1_Click()处理“计算”部分,这应该适合你。

一种更简单的编写方法是编写上下文命名的子例程,然后从单击处理程序中调用这些例程。

例子:

Private Sub Compute()
    'Do computations
    'Use a function instead of a sub if you need to return a value.
End Sub

Private Sub Summarize()
    If Not IsNumeric(TextBox6.Text) Or Not IsNumeric(TextBox7.Text) Or Not IsNumeric(TextBox8.Text) Or Not IsNumeric(TextBox9.Text) Then
        MessageBox.Show("Invalid Input", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    ElseIf 99 >= TextBox6.Text Or 99 >= TextBox7.Text Or 99 >= TextBox8.Text Or 99 >= TextBox9.Text Then
        MessageBox.Show("Invalid Amount", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    Else
        Form5.Show()
        Me.Hide()
        Form5.Label3.Text = TextBox1.Text
        Form5.Label5.Text = TextBox2.Text
        Form5.Label7.Text = TextBox3.Text
        Form5.Label9.Text = ComboBox1.Text
        Form5.Label11.Text = TextBox4.Text
        Form5.Label13.Text = ComboBox2.Text
        Form5.Label15.Text = Label27.Text
        Form5.Label22.Text = Label14.Text
        Form5.Label17.Text = Label22.Text
        Form5.Label19.Text = Label25.Text

    End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Compute() 'Call compute subroutine
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    Compute()   'Call compute subroutine
    Summarize() 'Call summarize subroutine
End Sub
于 2013-07-04T03:23:59.780 回答