vb输出数据到Excel
今天找了个双色球的全部组合vb代码,但是输出的是txt格式文件我想要它输出到Excel内.并且是一个单元格对应一个数字.该怎么修改这段代码????还有,因为双色球的组合较...
今天找了个双色球的全部组合vb代码,但是输出的是txt格式文件
我想要它输出到Excel内.并且是一个单元格对应一个数字.该怎么修改这段代码????还有,因为双色球的组合较多,怎么自动生成更多的工作簿以存据,????
以下是代码
Private Sub Command1_Click()
Dim Redball$(1 To 33), Blueball$(1 To 16)
Dim i%, j%, k%, l%, m%, n%, bi%, sl As Long, tmp
For i = 1 To 32
For j = 1 To 32
If j <> i Then
For k = 1 To 32
If k <> j And k <> i Then
For l = 1 To 32
If l <> k And l <> j And l <> i Then
For m = 1 To 32
If m <> l And m <> k And m <> j And m <> i Then
For n = 1 To 32
If n <> m And n <> l And n <> k And n <> j And n <> i Then
For bi = 1 To 16
tmp = i & " " & j & " " & k & " " & l & " " & m & " " & n & " " & bi '这里由于这几个变量本身就代表当前的值,所以直接用这几个变量就可以了,无须查找数组,用空格隔开
Open "d:\1.txt" For Append As #1
Print #1, tmp
Close #1
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
Next
End Sub 展开
我想要它输出到Excel内.并且是一个单元格对应一个数字.该怎么修改这段代码????还有,因为双色球的组合较多,怎么自动生成更多的工作簿以存据,????
以下是代码
Private Sub Command1_Click()
Dim Redball$(1 To 33), Blueball$(1 To 16)
Dim i%, j%, k%, l%, m%, n%, bi%, sl As Long, tmp
For i = 1 To 32
For j = 1 To 32
If j <> i Then
For k = 1 To 32
If k <> j And k <> i Then
For l = 1 To 32
If l <> k And l <> j And l <> i Then
For m = 1 To 32
If m <> l And m <> k And m <> j And m <> i Then
For n = 1 To 32
If n <> m And n <> l And n <> k And n <> j And n <> i Then
For bi = 1 To 16
tmp = i & " " & j & " " & k & " " & l & " " & m & " " & n & " " & bi '这里由于这几个变量本身就代表当前的值,所以直接用这几个变量就可以了,无须查找数组,用空格隔开
Open "d:\1.txt" For Append As #1
Print #1, tmp
Close #1
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
Next
End Sub 展开
展开全部
俺的亲娘嘞,你这代码得运行几年啊……你测试完过?算你有耐心……我可不行了,给你改进了改进,虽然还是得几个月吧……
=================
这个是输出到Excel表中的代码,建议你调试的时候,先把R常数改为10左右(10我已经等得不耐烦了,况且按你的32,Excel表根本盛不开),再加大。
Option Explicit
Private Const R As Integer = 32 '红球个数
Private Sub Command1_Click()
Dim i%, j%, k%, l%, m%, n%, bi%
Dim Ap As Object, Sht As Object, Z As Long
Set Ap = CreateObject("Excel.Application")
With Ap.Workbooks.Add
.Sheets(1).Delete
.Sheets(1).Delete
For i = 1 To R
Set Sht = .Worksheets.Add
Z = 0
For j = i + 1 To R
For k = j + 1 To R
For l = k + 1 To R
For m = l + 1 To R
For n = m + 1 To R
For bi = 1 To 16
Z = Z + 1
Sht.Cells(Z, 1).Value = i
Sht.Cells(Z, 2).Value = j
Sht.Cells(Z, 3).Value = k
Sht.Cells(Z, 4).Value = l
Sht.Cells(Z, 5).Value = m
Sht.Cells(Z, 6).Value = n
Sht.Cells(Z, 7).Value = bi
Next bi, n, m, l, k, j, i
Ap.Visible = True
End With
Set Sht = Nothing
Set Ap = Nothing
End Sub
=================
这个是输出到Excel表中的代码,建议你调试的时候,先把R常数改为10左右(10我已经等得不耐烦了,况且按你的32,Excel表根本盛不开),再加大。
Option Explicit
Private Const R As Integer = 32 '红球个数
Private Sub Command1_Click()
Dim i%, j%, k%, l%, m%, n%, bi%
Dim Ap As Object, Sht As Object, Z As Long
Set Ap = CreateObject("Excel.Application")
With Ap.Workbooks.Add
.Sheets(1).Delete
.Sheets(1).Delete
For i = 1 To R
Set Sht = .Worksheets.Add
Z = 0
For j = i + 1 To R
For k = j + 1 To R
For l = k + 1 To R
For m = l + 1 To R
For n = m + 1 To R
For bi = 1 To 16
Z = Z + 1
Sht.Cells(Z, 1).Value = i
Sht.Cells(Z, 2).Value = j
Sht.Cells(Z, 3).Value = k
Sht.Cells(Z, 4).Value = l
Sht.Cells(Z, 5).Value = m
Sht.Cells(Z, 6).Value = n
Sht.Cells(Z, 7).Value = bi
Next bi, n, m, l, k, j, i
Ap.Visible = True
End With
Set Sht = Nothing
Set Ap = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询