surebox
surebox

Reputation: 3

LOOPING GUI in Visual Studio

Can you help me with my problem in loop GUI in Visual Studio?

Need to happen is to put value for start textbox number 1 and must also put value for end textbox number 10 and also put value for step textbox number 2. In the combobox you will choose whether its for loop or do while or do until. Should appear in the textbox for the FOR LOOP is 2 4 6 8 10 and DO WHILE is 2 4 6 8 and to DO UNTIL 2 4 6 8.

Here's my code and i can't do the problem

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

this is the GUI

Upvotes: 0

Views: 333

Answers (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

You can do the same for WHILE LOOP and Until LOOP.

Valter

Upvotes: 1

Related Questions