Private Sub Command3_Click() '321,17,27 Dim i As Integer Dim j As Integer Const intLen As Integer = 321 Const aPer As Integer = 17 Const bPer As Integer = 27 Dim iMin As Integer Dim iLeft As Integer iMin = 99 For i = 0 To Int(intLen / aPer) iLeft = (intLen - aPer * i) Mod bPer If iLeft < iMin Then iMin = iLeft j = i End If Next MsgBox j & ":" & iMin End Sub
'修改了下msgbox. Private Sub Command3_Click() '321,17,27 Dim i As Integer Dim j As Integer Const intLen As Integer = 321 Const aPer As Integer = 17 Const bPer As Integer = 27 Dim iMin As Integer Dim iLeft As Integer iMin = 99 For i = 0 To Int(intLen / aPer) iLeft = (intLen - aPer * i) Mod bPer If iLeft < iMin Then iMin = iLeft j = i End If Next MsgBox intLen & "=" & aPer & "*" & j & "+" & bPer & "*" & Int((intLen - aPer * j) / bPer) & "余" & (intLen - aPer * j) Mod bPer End Sub
'321,17,27 Dim i As Integer
Dim j As Integer
Const intLen As Integer = 321
Const aPer As Integer = 17
Const bPer As Integer = 27
Dim iMin As Integer
Dim iLeft As Integer iMin = 99
For i = 0 To Int(intLen / aPer)
iLeft = (intLen - aPer * i) Mod bPer
If iLeft < iMin Then
iMin = iLeft
j = i
End If
Next
MsgBox j & ":" & iMin
End Sub
Private Sub Command3_Click()
'321,17,27 Dim i As Integer
Dim j As Integer
Const intLen As Integer = 321
Const aPer As Integer = 17
Const bPer As Integer = 27
Dim iMin As Integer
Dim iLeft As Integer iMin = 99
For i = 0 To Int(intLen / aPer)
iLeft = (intLen - aPer * i) Mod bPer
If iLeft < iMin Then
iMin = iLeft
j = i
End If
Next
MsgBox intLen & "=" & aPer & "*" & j & "+" & bPer & "*" & Int((intLen - aPer * j) / bPer) & "余" & (intLen - aPer * j) Mod bPer
End Sub
j, 用来存放当前残余最小的分割方法(即a材料多少段)
是你自己设置的一个用来比较大小的值
对不对