用vb6实现0-9字符串大数减小数差是6的所有排列的三位数(如006等),显示到text1文本框里。
1个回答
展开全部
实现代码如下:
Private Sub Command1_Click()
Dim i%, j%
Text1.Text = ""
For i = 1000 To 1999
If Picked(i) = True Then
j = j + 1
Text1.Text = Text1.Text & Right(i, 3) & " "
If j Mod 5 = 0 Then Text1.Text = Text1.Text & vbCrLf
End If
Next i
End Sub
Private Function Picked(Num As Integer) As Boolean
Dim n(1 To 3), i%, j%, m%
n(1) = Mid(Num, 2, 1)
n(2) = Mid(Num, 3, 1)
n(3) = Mid(Num, 4, 1)
For i = 1 To 3
For j = i + 1 To 3
If n(i) > n(j) Then
m = n(j)
n(j) = n(i)
n(i) = m
End If
Next j
Next i
If n(3) - n(2) - n(1) = 6 Then
Picked = True
Else
Picked = False
End If
End Function
运行结果如图
追答
自定义函数Picked里应将数组n显式声明为整型,这样才更为稳妥
Dim n(1 To 3) As Integer
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询