在Visual Studio中循环GUI

时间:2014-08-27 12:03:40

标签: vb.net visual-studio-2010 loops for-loop do-while

你能帮我解决Visual Studio中循环GUI中的问题吗?

需要发生的是为起始文本框号1设置值,并且还必须为结束文本框号10设置值,并且还为步骤文本框号2放置值。在组合框中,您将选择是for for循环还是执行while或do直到。应该出现在FOR LOOP的文本框中是2 4 6 8 10,DO WHILE是2 4 6 8和DO UNTIL 2 4 6 8。

这是我的代码,我无法解决问题

Public Class frmLimit

    Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
        Dim ctr As Integer
        For ctr = 0 To 50
            txtDisplay.Text = txtDisplay.Text & ctr & vbNewLine
        Next
        If cmboType.SelectedIndex = 0 Then
            MessageBox.Show("DO LOOP")
        ElseIf cmboType.SelectedIndex = 1 Then
            MessageBox.Show("WHILE LOOP")
        ElseIf cmboType.SelectedIndex = 2 Then
            MessageBox.Show("UNTIL LOOP")
        End If
    End Sub

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        txtStart.Clear()
        txtEnd.Clear()
        txtStep.Clear()
        txtDisplay.Clear()
        cmboType.SelectedIndex = -1
    End Sub

    Private Sub frmLimit_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        Application.Exit()
    End Sub
End Class

这是GUI

1 个答案:

答案 0 :(得分:1)

Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
    Dim ctr As Integer

    If cmboType.SelectedIndex = 0 Then
        If IsNumeric(txtStart.Text) And IsNumeric(txtEnd.Text) And IsNumeric(txtStep.Text) Then
            For ctr = CInt(txtStart.Text) To CInt(txtEnd.Text) Step CInt(txtStep.Text) 
                txtDisplay.Text += ctr.ToString + " "
            Next

            txtDisplay.Text += vbNewLine
        Else
            'Error message
        End If

        MessageBox.Show("FOR LOOP")
    ElseIf cmboType.SelectedIndex = 1 Then
        MessageBox.Show("WHILE LOOP")
    ElseIf cmboType.SelectedIndex = 2 Then
        MessageBox.Show("UNTIL LOOP")
    End If
End Sub

您可以对WHILE LOOPUntil LOOP执行相同操作。

瓦尔特