作业帮 > 综合 > 作业

用VB,用VB,用VB将123456789这九个数字分成三个三位数,各个数字之间比例是1:2:3

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 03:20:40
用VB,用VB,用VB将123456789这九个数字分成三个三位数,各个数字之间比例是1:2:3
用VB将123456789九个数字分成三个三位数,要求各个数字不重复,且第一个数字是第二个的两倍,是第三个的三倍,问应该怎样分?
知道的大神请把文件上传给我,Thank you verymuch///////我需要的是工程和窗体文件
用VB,用VB,用VB将123456789这九个数字分成三个三位数,各个数字之间比例是1:2:3
Private Sub Command1_Click()
Dim tmpStr As String,tmpStr1 As String
Dim mpStr2 As String,tmpStr3 As String
Dim a As Integer,b As Integer,c As Integer
Dim a1 As String,b1 As String,c1 As String
Dim Sum1 As Integer,Sum2 As Integer,Sum3 As Integer
tmpStr = "123456789"
For a = 1 To 9
tmpStr1 = Replace(tmpStr,a,"") '去掉已经用的数
For b = 1 To 8
b1 = Mid(tmpStr1,b,1)
tmpStr2 = Replace(tmpStr1,b1,"") '去掉已经用的数
For c = 1 To 7
c1 = Mid(tmpStr2,c,1)
Sum1 = Val(a & b1 & c1) '得到最小的三位数
' 如果最小三位数的三倍大于999,结束计算
If Sum1 > 333 Then GoTo theEnd
Sum2 = Sum1 * 2 '得到第二个数
If CheckSum(CLng(Sum1),Sum2) Then '如果第二个数合格
Sum3 = Sum1 * 3 '得到第三个数
If CheckSum(CLng(Sum1 & Sum2),Sum3) Then '如果合格,输出
Debug.Print Sum3 & "," & Sum2 & "," & Sum1
End If
End If
Next
Next
Next
theEnd:
End Sub
'检查重复数字
Private Function CheckSum(ByVal aSum As Long,ByVal bSum As Integer) As Boolean
Dim I As Integer
For I = 1 To 3
If InStr(aSum,Mid(bSum,I,1)) > 0 Then
Exit Function
End If
Next
CheckSum = True
End Function