Private Sub txtSyuksu_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSyuksu1.Validated, txtSyuksu2.Validated, txtSyuksu3.Validated, txtSyuksu4.Validated, txtSyuksu5.Validated, txtSyuksu6.Validated, txtSyuksu7.Validated, txtSyuksu8.Validated, txtSyuksu9.Validated Dim kingaku As Decimal Dim i As Integer i = Syuksu_Focus() '現在フォーカスのあるtxtSyuksu?の位置を取得 If Panel1.Controls("txtSyuksu" & i).Text = "" Or Panel1.Controls("txtGtanka" & i).Text = "" Then Exit Sub End If kingaku = CDec(Panel1.Controls("txtSyuksu" & i).Text) * CDec(Panel1.Controls("txtGtanka" & i).Text) Panel1.Controls("txtGkin" & i).Text = kingaku End Sub Private Sub txtSyuksu_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtSyuksu1.Validating, txtSyuksu2.Validating, txtSyuksu3.Validating, txtSyuksu4.Validating, txtSyuksu5.Validating, txtSyuksu6.Validating, txtSyuksu7.Validating, txtSyuksu8.Validating, txtSyuksu9.Validating Dim i As Integer Dim wkHatsu As Decimal Dim wkSyuksu As Decimal Dim RET As Integer i = Syuksu_Focus() '現在フォーカスのあるtxtSyuksu?の位置を取得 If Panel1.Controls("txtHatsu" & i).Text = "" Or Panel1.Controls("txtSyuksu" & i).Text = "" Then Exit Sub End If wkHatsu = CDec(Panel1.Controls("txtHatsu" & i).Text) wkSyuksu = CDec(Panel1.Controls("txtsyuksu" & i).Text) If wkHatsu < wkSyuksu Then RET = MsgBox("発注数より多いのですか?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "確認") If RET = vbNo Then e.Cancel = True End If End If End Sub Private Function Syuksu_Focus() As Integer Dim i As Integer = 1 Select Case True Case txtSyuksu1.Focused = True i = 1 Case txtSyuksu2.Focused = True i = 2 Case txtSyuksu3.Focused = True i = 3 Case txtSyuksu4.Focused = True i = 4 Case txtSyuksu5.Focused = True i = 5 Case txtSyuksu6.Focused = True i = 6 Case txtSyuksu7.Focused = True i = 7 Case txtSyuksu8.Focused = True i = 8 Case txtSyuksu9.Focused = True i = 9 End Select Return i End Function