我正在研究一个名为Algoritm彩票的项目,该项目可以在Softpedia网站上找到,我希望在文本框中显示数字和奇数。我该怎么办?例:
Textbox1.Text = {1,2,3,4,5,6,7,8,9,10
输出:Impare1.Text = 1,3,5,7,9
输出:Pare1.Text = 2,4,6,8,10
Textbox2.Text = 11,12,13,14,15,16,17,18,19,20
Impare2.Text = 11,13,15,17,19
Pare2.Text = 12,14,16,18,20
让类似这样的东西:该代码用于连续数字。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim number As Integer
Dim numbers As New List(Of Integer)
For Each strNum As String In TextBox1.Text.Split(",")
If Integer.TryParse(strNum.Trim, number) Then
numbers.Add(number)
End If
Next
numbers.Sort()
For seriesLength As Integer = 2 To numbers.Count
Dim ctl As Control = Me.Controls.Find("TextBox" & seriesLength, True).FirstOrDefault
If TypeOf (ctl) Is TextBox Then
Dim tb As TextBox = DirectCast(ctl, TextBox)
tb.Clear()
For i As Integer = 0 To (numbers.Count - seriesLength)
If (numbers(i + (seriesLength - 1)) - numbers(i)) = (seriesLength - 1) Then
tb.AppendText(String.Join(",", numbers.GetRange(i, seriesLength)) & vbCrLf)
End If
Next
End If
Next
End Sub
答案 0 :(得分:-1)
要确定数字是奇数还是偶数,可以将其除以2,然后将数字的整数除以2,然后将一个与另一个进行比较,如果它们匹配则为偶数...
所以您的if问题应该是这样
If (TestNumber / 2) = Int(TestNumber / 2) Then
'Number is even
txtImpare.text = txtImpare.Text & "," & Str(TestNumber)
Else
.Number is odd
txtPare.text = txtPare.Text & "," & Str(TestNumber)
End If
对您有意义的希望