VB代码 12个文字随机2个文字组合,不重复.

比如说 子,丑,寅,卯,辰,巳,午,未,申,酉,戌,亥,
2个一组,但是不重复,总共是不是有66组? 列出来.

子,丑,
寅,卯,
辰,巳,
午,未,
申,酉,
戌,亥,

丑,寅,
卯,辰,
巳,午,
未,申,
酉,戌,
亥,子,

..省略
能不能像这样分开每组列出来? 每一组12个,不重复.
第1组
子,丑,
寅,卯,
辰,巳,
午,未,
申,酉,
戌,亥,

第2组
丑,寅,
卯,辰,
巳,午,
未,申,
酉,戌,
亥,子,

第3组
....省略

我胡汉山又回来啦!!!!! 这回来真的了。把不重复的我都搞上去了。四亿多个,多了不要骂我,这个可费了我点时间,其实并不难。运行下试试,记得不要骂我!

Option Base 1

Private Sub Form_Activate()
Dim a
a = Array("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥")
Dim a1(11) '这个程真的不太好编,要看就看死你 ,呵呵!!!!四亿多个
Dim a2(10)
Dim a3(9)
Dim a4(8)
Dim a5(7)
Dim a6(6)
Dim a7(5)
Dim a8(4)
Dim a9(3)
Dim a10(2)
For i = 1 To 12 'a(i)
For j = 1 To 12
If j <> i Then
x = x + 1
a1(x) = a(j) 't 11
If x = 11 Then x = 0
End If
Next j
For i1 = 1 To 11
no1 = a1(i1) 'no1 10
For j1 = 1 To 11
If a1(j1) <> no1 Then
X1 = X1 + 1
a2(X1) = a1(j1) 't 10
If X1 = 10 Then x = 0
End If
Next j1
For i2 = 1 To 10
no2 = a2(i2)
For j2 = 1 To 10
If a2(j2) <> no2 Then
X2 = X2 + 1
a3(X2) = a2(j2)
If X2 = 9 Then X2 = 0
End If
Next j2
For i3 = 1 To 9
no3 = a3(i3)
For j3 = 1 To 9
If a3(j3) <> no3 Then
X3 = X3 + 1
a4(X3) = a3(j3)
If X3 = 8 Then X3 = 0
End If
Next j3

For i4 = 1 To 8
no4 = a4(i4)
For j4 = 1 To 8
If a4(j4) <> no4 Then
X4 = X4 + 1
a5(X4) = a4(j4)
If X4 = 7 Then X4 = 0
End If
Next j4

For i5 = 1 To 7
no5 = a5(i5)
For j5 = 1 To 7
If a5(j5) <> no5 Then
X5 = X5 + 1
a6(X5) = a5(j5)
If X5 = 6 Then X5 = 0
End If
Next j5
For i6 = 1 To 6
no6 = a6(i6)
For j6 = 1 To 6

If a6(j6) <> no6 Then
X6 = X6 + 1
a7(X6) = a6(j6)
If X6 = 5 Then X6 = 0
End If
Next j6
For i7 = 1 To 5
no7 = a7(i7)
For j7 = 1 To 5
If a7(j7) <> no7 Then
x7 = x7 + 1
a8(x7) = a7(j7)
If x7 = 4 Then x7 = 0
End If
Next j7

For i8 = 1 To 4
no8 = a8(i8)
For j8 = 1 To 4
If a8(j8) <> no8 Then
x8 = x8 + 1
a9(x8) = a8(j8)
If x8 = 3 Then x8 = 0
End If
Next j8
For i9 = 1 To 3
no9 = a9(i9)
For j9 = 1 To 3
If a9(j9) <> no9 Then
x9 = x9 + 1
a10(x9) = a9(j9)
If x9 = 2 Then x9 = 0
End If
Next j9
For i10 = 1 To 2

Select Case i10
Case 1
Print a(i); no1 & "." & no2; no3 & "." & no4; no5 & "." & no6; no7 & "." & no8; no9 & "." & a10(1); a10(2); Space(2);
Case 2
Print a(i); no1 & "." & no2; no3 & "." & no4; no5 & "." & no6; no7 & "." & no8; no9 & "." & a10(2); a10(1); Space(2);
End Select
xyz = xyz + 1
asd = asd + 1
If asd = 250 Then

MsgBox "下一页"
asd = 0
Cls
End If
If xyz = 5 Then
Print
xyz = 0
End If

Next i10

Next i9

Next i8
Next i7
Next i6
Next i5
Next i4
Next i3
Next i2
Next i1
Next i
End Sub

Private Sub Form_Load()
Form1.WindowState = 2
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-04-16
Private Sub Command1_Click()
Dim s As String
Dim TGan(12) As String
Dim i As Integer
Dim k As Integer
Dim j As Integer
TGan(1) = "子"
TGan(2) = "丑"
TGan(3) = "寅"
TGan(4) = "卯"
TGan(5) = "辰"
TGan(6) = "巳"
TGan(7) = "午"
TGan(8) = "未"
TGan(9) = "申"
TGan(10) = "酉"
TGan(11) = "戌"
TGan(12) = "亥"
For i = 1 To 12
For k = 1 To 12
j = j + 1
s = s & TGan(i) & TGan(k) & " "
If k = 12 Then s = s & Chr(13) & Chr(13)
Next
Next
MsgBox s, , "一共" & j & "组"
End Sub
第2个回答  2009-04-16
共66组
子丑 子寅 子卯 子辰 子巳 子午 子未 子申 子酉 子戌 子亥 丑寅 丑卯 丑辰 丑巳 丑午 丑未 丑申 丑酉 丑戌 丑亥 寅卯 寅辰 寅巳 寅午 寅未 寅申 寅酉 寅戌 寅亥 卯辰 卯巳 卯午 卯未 卯申 卯酉 卯戌 卯亥 辰巳 辰午 辰未 辰申 辰酉 辰戌 辰亥 巳午 巳未 巳申 巳酉 巳戌 巳亥 午未 午申 午酉 午戌 午亥 未申 未酉 未戌 未亥 申酉 申戌 申亥 酉戌 酉亥 戌亥
借用一下楼上的成果
Dim TGan(12) As String

Private Sub Form_Load()

TGan(1) = "子"
TGan(2) = "丑"
TGan(3) = "寅"
TGan(4) = "卯"
TGan(5) = "辰"
TGan(6) = "巳"
TGan(7) = "午"
TGan(8) = "未"
TGan(9) = "申"
TGan(10) = "酉"
TGan(11) = "戌"
TGan(12) = "亥"

End Sub

Private Sub Form_Activate()
Dim k As Integer
k = 0
Text1.Text = ""
For i = 1 To 12 - 1
For j = i + 1 To 12
k = k + 1
Text1.Text = Text1.Text & TGan(i) + TGan(j) & " "
Next
Next
Print k
End Sub
第3个回答  2009-04-26
子丑
子寅
子卯
子辰
子巳
子午
子未
子申
子酉
子戌
子亥

丑寅
丑卯
丑辰
丑巳
丑午
丑未
丑申
丑酉
丑戌
丑亥
寅卯
寅辰

寅巳
寅午
寅未
寅申
寅酉
寅戌
寅亥
卯辰
卯巳
卯午
卯未
卯申

卯酉
卯戌
卯亥
辰巳
辰午
辰未
辰申
辰酉
辰戌
辰亥
巳午
巳未

巳申
巳酉
巳戌
巳亥
午未
午申
午酉
午戌
午亥
未申
未酉
未戌

未亥
申酉
申戌
申亥
酉戌
酉亥
戌亥

共有66组数据

Dim TGan(12) As String

Private Sub Form_Load()

TGan(1) = "子"
TGan(2) = "丑"
TGan(3) = "寅"
TGan(4) = "卯"
TGan(5) = "辰"
TGan(6) = "巳"
TGan(7) = "午"
TGan(8) = "未"
TGan(9) = "申"
TGan(10) = "酉"
TGan(11) = "戌"
TGan(12) = "亥"

End Sub

Private Sub Form_Activate()
Dim k, num As Integer
k = 0
num = 0
Text1.Text = ""
For i = 1 To 12
For j = i + 1 To 12
k = k + 1
If k = 12 Then
k = 0
Text1.Text = Text1.Text & vbCrLf
End If
num = num + 1
Text1.Text = Text1.Text + TGan(i) + TGan(j) & vbCrLf
Next
Next
Text1.Text = Text1.Text + vbCrLf + "共有" + CStr(num) + "组数据"
End Sub

VB代码 12个文字随机2个文字组合,不重复.
a = Array("子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥")Dim a1(11) '这个程真的不太好编,要看就看死你 ,呵呵!!!四亿多个 Dim a2(10)Dim a3(9)Dim a4(8)Dim a5(7)Dim a6(6)Dim a7(5)Dim a8(4)Dim a9(3)Dim a10(...

用vb生成随机字符串
你可以随机从ASCII码中的33到126之间随机选一个数 然后还原成字符 重复12次就可以得到12位随机字符串了~使用rnd函数 为了生成某个范围内的随机整数,可使用以下公式 Int((upperbound - lowerbound + 1) * Rnd + lowerbound)upperbound 是随机数范围的上限,而 lowerbound 则是随机数范围的下限 Int...

需要一个1-12随机抽号(不可重复)的vb小程序 界面清晰 美观 1天内要...
Dim stmp As String Dim k As Integer Private Sub Form_Load()k = 0 End Sub Private Sub Command5_Click()Dim s1 As String, s As Integer Randomize Time()If stmp = "" Then stmp = ","Do While k < 12 s = Int(Rnd * (12 - 1 + 1) + 1)If InStr(1, stmp, "," &...

用VB 做一个随机抽名字。随机从所有人名字里中选取2个人的名字,这2个 ...
Print "第一个:" & xm(x) & " 第二个:" & xm(y)End Sub 添加个按扭即可 名字的值自己赋

用VB做一个姓名随机抽取的软件 但是 名字不能重复抽取谢谢
UBound(a) - 1 If x = a(j) Then i = i - 1: Exit For '判断是否重复 Next Next For i = 0 To UBound(a) List2.AddItem List1.List(a(i)) 'list1内抽取到的添加到list2,右边的 list1 和 list2 自己改 NextEnd Sub ...

vb 判断是否重复,不重复的文字记录
'检查重复的函数,主程序调用这个函数来检查是否重复 Private Function findRepeat(str As String)For i = 0 To List1.ListCount If str = List1.List(i) Then findRepeat = True Exit Function End If Next findRepeat = False End Function '点击按钮,检查重复,如果不重复就添加 Private Sub ...

VB编程求助(生成不重复的随机数)
hell_faller的答案有可能出现0,不符合楼主要求 tw314809的只能防止出现连续重复,无法防止隔数重复,比如 1 2 1 2 1 2 langelos的答案是正解 如果要代码量较少的答案,那就是下面的:Dim a() As String, s As String, i As Integer, n As Integer Randomize For i = 1 To 60 Do n = ...

需要一个1-12随机抽号(不可重复)的vb小程序 界面清晰 美观 1天内要...
我这里有一个,不知道和不和你的要求,我的联系方式:3_5_8*3756_88

VB中产生几个不重复的随机数字,(尽量要简单点)
MsgBox n(0) & "," & n(1) & "," & n(2) & "," & n(3) & "," & n(4) & "," & n(5) & "," & n(6) & "," & n(7) & "," & n(8) & "," & n(9) & "," & n(10) & ","End Sub Function abc(ByVal i As Integer) As Integer Randomize a ...

vb如何出现不重复的几个随机数
'编制:xsfhlzh '功能:取NumMin到NumMax间的n个随机整数 '说明:取数标志数组是Byte,每一位表示NumMin到NumMax间某个数的状态 Dim arr() As Integer If n > NumMax - NumMin + 1 Then ReDim arr(0)arr(0) = 0 Else ReDim arr(n)Dim b() As Byte Dim m As Integer m = Int((...

相似回答