我是一个视觉基本的新手,我有一些困扰我很长时间的任务。我不知道有谁可以要求提示,所以我希望这里有一些好人能给我一个如何解决这个问题的线索。
请注意,我是非常新的,请不要粗暴对我。我需要一些"写数字比它之前的数字/数字更大的例子" 我不是很擅长英语,所以我不能很好地解释它或搜索例子。
重点是我有6个值,我需要测试并将其写入列表框,值女巫比之前的所有值都大(不是在它之后和之后的数量)
Public Class Form1
Private strClasses(5) As String
Private Sub Buttonaddarray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonaddarray.Click
clearlist()
strClasses(0) = Val(InputBox("Unesite visinu prvog covjeka"))
strClasses(1) = Val(InputBox("Unesite visinu drugog covjeka"))
strClasses(2) = Val(InputBox("Unesite visinu treceg covjeka"))
strClasses(3) = Val(InputBox("Unesite visinu cetvrtog covjeka"))
strClasses(4) = Val(InputBox("Unesite visinu petog covjeka"))
strClasses(5) = Val(InputBox("Unesite visinu sestog covjeka"))
For i As Integer = 0 To strClasses.Length - 1
listarray.Items.Add(strClasses(i))
Next
End Sub
Private Sub clearlist()
listarray.Items.Clear()
End Sub
Private Sub Buttonsort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonsort.Click
clearlist()
Dim a As Integer = strClasses(0)
Dim b As Integer = strClasses(1)
Dim c As Integer = strClasses(2)
Dim d As Integer = strClasses(3)
Dim f As Integer = strClasses(4)
Dim g As Integer = strClasses(5)
listarray.Items.Add("Blagajnik vidi ljude sledećih visina")
listarray.Items.Add(a)
If b > a Then
listarray.Items.Add(b)
End If
If c > a And c > b Then
listarray.Items.Add(c)
End If
If d > a And d > b And d > c Then
listarray.Items.Add(d)
End If
If f > a And f > b And f > c And f > d Then
listarray.Items.Add(f)
End If
If g > a And g > b And g > c And g > d And g > f Then
listarray.Items.Add(g)
End If
End Sub
结束班
答案 0 :(得分:1)
这应该返回您正在寻找的结果。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strClasses(5) As Integer
strClasses(0) = 1
strClasses(1) = 2
strClasses(2) = 1
strClasses(3) = 5
strClasses(4) = 6
Debug.Print(maxOutArray(strClasses))
strClasses(0) = 10
strClasses(1) = 5
strClasses(2) = 6
strClasses(3) = 9
strClasses(4) = 11
Debug.Print(maxOutArray(strClasses))
End Sub
Private Function maxOutArray(values() As Integer) As String
Dim currentHightest As Integer
Dim returnVal As String = String.Empty
For Each parseInt As Integer In values
If parseInt > currentHightest Then
currentHightest = parseInt
returnVal = String.Concat(returnVal, " ", currentHightest)
End If
Next
Return returnVal
End Function