用VB,,用VB,用VB将123456789这九个数字分成三个三位数,各个数字之间比例是1:2:3
用VB将123456789九个数字分成三个三位数,要求各个数字不重复,且第一个数字是第二个的两倍,是第三个的三倍,问应该怎样分?
知道的大神请把文件上传给我,,,Thank you verymuch///////我需要的是工程和窗体文件<.vbp和.frm文件>
如果“第一个数字是第二个的两倍,是第三樱兆个的三倍”则本题无解,如果“第二个数字是第一个数字的拆巧两倍,第三个数字是旅颂键第一个数字的三倍”则解如下:
Private Sub Command1_Click()
Dim a1 As Integer, a2 As Integer, a3 As Integer, myNum1 As Integer, myNum2 As Integer, myNum3 As Integer, myTempStr As String, myOutput As String, i As Integer
For a1 = 1 To 9
For a2 = 1 To 9
For a3 = 1 To 9
myNum1 = Val(a1 & a2 & a3)
myNum2 = 2 * myNum1
myNum3 = 3 * myNum1
If myNum2 > 999 Or myNum3 > 999 Then GoTo myEndSub
myTempStr = CStr(myNum1) & CStr(myNum2) & CStr(myNum3)
For i = 1 To 9
If InStr(1, myTempStr, i) = 0 Then GoTo myNextOne
Next
myOutput = myOutput & myNum1 & vbTab & myNum2 & vbTab & myNum3 & vbCrLf
myNextOne:
Next
Next
Next
myEndSub:
MsgBox myOutput
End Sub
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
群 号:238706019里面问问