求高手用VB语言写个小程序,谢谢
从1,2,3,4,,,,,20里随机选3个数,这三个数的和大于10小于18,谢谢还请分享源码,谢谢...
从1,2,3,4,,,,,20里随机选3个数,这三个数的和大于10小于18,谢谢
还请分享源码,谢谢 展开
还请分享源码,谢谢 展开
展开全部
Option Explicit
Private Sub Command1_Click()
Cls
Dim a() As Integer
GetNewData a
Dim s As Variant
For Each s In a
Print s '输出结果
Next
End Sub
Function GetNewData(ByRef a() As Integer)
ReDim a(0)
Dim temp As Integer, s As Variant, exists As Boolean, sum As Integer
Do While UBound(a) < 3
DoEvents
Randomize
temp = Int(Rnd * 20) + 1
exists = False
For Each s In a
If s = temp Then exists = True
Next
If Not exists Then
a(UBound(a)) = temp
ReDim Preserve a(UBound(a) + 1)
End If
sum = 0
If UBound(a) = 3 Then
For Each s In a
sum = sum + s
Next
If sum <= 10 Or sum >= 18 Then ReDim a(0)
end if
Loop
ReDim Preserve a(UBound(a) - 1)
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询