很多文本框中的延迟数量VB.Net

时间:2019-01-26 00:53:24

标签: vb.net

我想在文本框中显示尚未提取的对应值(从1到80)。 (延迟):)这段代码对我来说不起作用,它应该扫描该文本框中的所有80个数字,看是否存在,并且发生了什么。如果该数字不存在,则应将其延迟到在该文本框中找到该数字时最接近的值。仅当该文本框中存在该数字时,此代码才有效,然后添加+1值,但是如何处理延迟?在80个TxtIntDraws框中,扫描80个数字(每个TxtIntDraws文本框中有20个数字/ 80)-在80个TxtNonExtr文本框中,从1到80,将显示相应的值。

  Private Sub ScanNonExtrNum()
        Dim numberArray() As Integer = Enumerable.Range(1, 80).ToArray
        Dim lstDrawTextBoxes As New List(Of TextBox)
        Dim intToTest As Integer
        Dim lstNumberExists As New List(Of Integer)
        For i = 1 To Val(txtDrawsCount.Text) - 1
            lstDrawTextBoxes.Add(CType(TabControl2.TabPages(2).Controls("TxtIntDraws" & i.ToString), TextBox))
        Next
        On Error Resume Next
        For Each t As TextBox In lstDrawTextBoxes
            Dim textArray() As String = t.Text.Split(","c)
            For index As Integer = 0 To textArray.Length - 1
                If Integer.TryParse(textArray(index).Trim, intToTest) Then
                    If numberArray.Contains(intToTest) Then
                        lstNumberExists.Add(intToTest)
                        Dim txtBox As TextBox = (CType(TabControl2.TabPages(4).Controls("TxtNonExtr" & intToTest.ToString), TextBox))
                    Else
                        Dim txtBox As TextBox = (CType(TabControl2.TabPages(4).Controls("TxtNonExtr" & intToTest.ToString), TextBox))
                        txtBox.Text = Val(txtBox.Text) + 1
                    End If
                End If
            Next
        Next
    End Sub

我应该如何使用此代码?

示例:我有:

TxtIntDraws1.Text = 1,2,3,9
TxtIntDraws2.Text = 1,2,4,10
TxtIntDraws3.Text = 1,2,4,8

Numbers: 5,6,7 = 3 delays.
Number 4: 1 delays.
Number 8 - 2 delays.
Number 10: 1 delays.
TxtNonExtr4.Text = 1
TxtNonExtr5.Text = 3 
TxtNonExtr6.Text = 3 
TxtNonExtr7.Text = 3 
TxtNonExtr8.Text = 2
TxtNonExtr10.Text = 1

如何?

1 个答案:

答案 0 :(得分:0)

我〜认为〜现在我了解了规格。试试看:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim tb As TextBox
    Dim ctl As Control
    Dim number As Integer
    Dim curDraws As New List(Of Integer)
    Dim delays As New Dictionary(Of Integer, Integer)

    ' Set all Delays to an initial value 0:
    For d As Integer = 1 To 80
        delays.Add(d, 0)
    Next

    ' Go backwards through the TextBoxes, TxtInDraws80 to TxtInDraws1,
    ' and build a List(Of Integer) from the values in each of them:
    For i As Integer = 80 To 1 Step -1
        ctl = Me.Controls.Find("TxtIntDraws" & i, True).FirstOrDefault
        If Not IsNothing(ctl) AndAlso TypeOf ctl Is TextBox Then
            tb = DirectCast(ctl, TextBox)
            curDraws.Clear()
            For Each strNum As String In tb.Text.Split(",")
                If Integer.TryParse(strNum.Trim, number) Then
                    curDraws.Add(number)
                End If
            Next

            ' Go through the draw values, 1 to 80, and see if they exist in our current list.
            ' If they do, reset the delay to 0, otherwise increment it by 1:
            For draw As Integer = 1 To 80
                If curDraws.Contains(draw) Then
                    delays(draw) = 0
                Else
                    delays(draw) = delays(draw) + 1
                End If
            Next
        End If
    Next

    ' Output the delay results to TxtNonExtr1 through TxtNonExtr80:
    For Each kvp As KeyValuePair(Of Integer, Integer) In delays
        ctl = Me.Controls.Find("TxtNonExtr" & kvp.Key, True).FirstOrDefault
        If Not IsNothing(ctl) AndAlso TypeOf ctl Is TextBox Then
            tb = DirectCast(ctl, TextBox)
            tb.Text = delays(kvp.Value)
        End If
    Next
End Sub