注册 登录
编程论坛 VB.NET论坛

vb.net编写 我刚学不太懂

wangwubing 发布于 2008-10-18 18:06, 1135 次点击
随机产生20个学生的成绩,统计各分数段人数。即0—59、60—69、70—79、80—89、90—100,并显示结果。产生的数据在Label1中显示,统计结果在Label2中显示。
2 回复
#2
fairy42008-10-20 19:30
Dim rom As New Random
        Dim romcount As Integer
        Dim str As String
        Dim arr() As String
        Dim int60, int70, int80, int90, int100, intx As Int32
        ReDim arr(20)
        For x As Integer = 0 To 19
            romcount = rom.Next(0, 100)
            arr(x) = romcount
        Next
        For x As Integer = 0 To 19
            Application.DoEvents()
            str &= ";" & CStr(arr(x))
            intx = CInt(arr(x))
            Application.DoEvents()
            If 0 < intx And intx <= 59 Then
                int60 += 1
            ElseIf 60 <= intx And intx <= 69 Then
                int70 += 1
            ElseIf 70 <= intx And intx <= 79 Then
                int80 += 1
            ElseIf 80 <= intx And intx <= 89 Then
                int90 += 1
            ElseIf 90 <= intx And intx <= 100 Then
                int100 += 1
            End If
        Next

        Me.Label1.Text = str
        Me.Label2.Text = "0-59人数为:" & int60 & Chr(10) & _
        "60-69人数为:" & int70 & Chr(10) & _
        "70-79人数为:" & int80 & Chr(10) & _
        "80-89人数为:" & int90 & Chr(10) & _
        "90-100人数为:" & int100 & Chr(10)
有时候自己动手学的更快
#3
wangwubing2008-10-22 15:03
谢谢啊,我也要好好的学了啊!
1