Safa Sory Ответов: 1

Я хочу уменьшить строки этой программы пожалуйста помогите


Private Sub btn_tarqeya_Click(sender As System.Object, e As System.EventArgs) Handles btn_years_inc.Click
        Dim cur_degree As Integer = Val(txt_cur_degree.Text)
        Dim cur_years As Integer = Val(txt_cur_years.Text)
        Dim new_degree As Integer = Val(txt_new_degree.Text)
        Dim new_years As Integer = Val(txt_new_years.Text)
        Select Case cur_degree
            Case 1
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt1s.Text) + Val(txt1inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 2
                        txt_new_salary.Text = Val(txt2s.Text)
                End Select
            Case 2
                 Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt2s.Text) + Val(txt2inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 3
                        txt_new_salary.Text = Val(txt3s.Text)
                End Select
            Case 3
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt3s.Text) + Val(txt3inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 4
                        txt_new_salary.Text = Val(txt4s.Text) 
                End Select
            Case 4
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt4s.Text) + Val(txt4inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 5
                        txt_new_salary.Text = Val(txt5s.Text)
                End Select
            Case 5
                 Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt5s.Text) + Val(txt5inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 6
                        txt_new_salary.Text = Val(txt5s.Text)
            Case 6
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt6s.Text) + Val(txt6inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 7
                        txt_new_salary.Text = Val(txt7s.Text)
                End Select
            Case 7
                 Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt7s.Text) + Val(txt7inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 8
                        txt_new_salary.Text = Val(txt8s.Text)
                End Select
            Case 8
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt8s.Text) + Val(txt8inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 9
                        txt_new_salary.Text = Val(txt9s.Text) 
                End Select
            Case 9
                 Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt9s.Text) + Val(txt9inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 10
                        txt_new_salary.Text = Val(txt10s.Text) 
                End Select
            Case 10
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt10s.Text) + Val(txt10inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 11
                        txt_new_salary.Text = Val(txt11s.Text)
                End Select
            Case 11
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt11s.Text) + Val(txt11inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 12
                        txt_new_salary.Text = Val(txt12s.Text)
                End Select

                End Select
            Case 12
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt12s.Text) + Val(txt12inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 13
                        txt_new_salary.Text = Val(txt13s.Text)
                End Select
            Case 13
                 Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt13s.Text) + Val(txt13inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 14
                        txt_new_salary.Text = Val(txt14s.Text)
                End Select
            Case 14
                Select Case cur_years
                    Case 1
                        txt_new_years.Text = 2
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text)
                    Case 2
                        txt_new_years.Text = 3
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 2
                    Case 3
                        txt_new_years.Text = 4
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 3
                    Case 4
                        txt_new_years.Text = 5
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 4
                    Case 5
                        txt_new_years.Text = 6
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 5
                    Case 6
                        txt_new_years.Text = 7
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 6
                    Case 7
                        txt_new_years.Text = 8
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 7
                    Case 8
                        txt_new_years.Text = 9
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 8
                    Case 9
                        txt_new_years.Text = 10
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 9
                    Case 10
                        txt_new_years.Text = 0
                        txt_new_degree.Text = 14
                        txt_new_salary.Text = Val(txt14s.Text) + Val(txt14inc.Text) * 9
                End Select

        End Select


    End Sub

    
End Class


Что я уже пробовал:

спасибо за помощь, извините, у меня слабый английский.пожалуйста, помогите мне
я буду exolaine mean of textboxes.txtbox1s-это первая зарплата перед инкрементом .после каждого года мы увеличиваем зарплату на значение txt1inc .каждый год имеет значение инкремента.после десяти лет мы делаем новый "класс" для employ txt_degree-это класс,cur degree-это текущий класс.спасибо

1 Ответов

Рейтинг:
1

CPallini

Вы должны использовать массивы элементов управления (например, txts(5) вместо txt5s) и арифметических соотношений, чтобы уменьшить все то Case вещи, чтобы

If cur_years < 10 Then
  txt_new_years.Text = cur_years + 1
  txt_new_salary.Text = Val(txts(cur_degree).Text) + Val(txtinc(cur_degree).Text) * cur_years
ElseIf cur_years = 10 Then
  txt_new_years.Text = 0
  txt_new_degree.Text = cur_degree + 1
  txt_new_salary.Text = Val(txts(cur_degree + 1).Text)
Else
  ' handle error here
End


Laxmidhar tatwa technologies

хорошая техника для сокращения кода