| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 624 人关注过本帖
标题:•新手,求问VB6的编程问题
只看楼主 加入收藏
warosng
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-10-6
收藏
 问题点数:0 回复次数:3 
•新手,求问VB6的编程问题
我菜鸟什么都不懂(不知什么时侯才学懂),请神人在每句能详细解释,因我菜鸟什么都不懂。
Sub DataSplit()
    m = Sheet1.[a1].End(4).Row
    arr = Sheet1.[c1].Resize(m, 5)
    ReDim brr(2 To m, 1 To 11)
    For i = 2 To m
        For j = 1 To 5
            t = arr(i, j)
            brr(i, t) = t
        Next
    Next
    Sheet1.[h2].Resize(m - 1, 11) = brr
End Sub
Sub kagawa()
    Dim i&, j&, k&, h&, m&, n&, Ac&, r&, s$, t, cnt&
    tms = Timer
   
    m = 11: n = 8: Ac8 = (m, n)
    ReDim Combin8&(1 To Ac8, 1 To m)
    Call GetCombinArr(Combin8, m, n)
   
    Sheet1.Activate
    m = Sheet1.[a1].End(4).Row
    arr = Sheet1.[c1].Resize(m, 5)
'    Sheet2.Activate
    ReDim brr&(2 To m, 1 To 5)
    For i = 2 To m
        For j = 1 To 5
            brr(i, j) = arr(i, j)
        Next
    Next
   
    ReDim crr(1 To Ac8, 1 To m)
    For k = 1 To Ac8
        cnt = 0
        For i = 2 To m
            r = 0
            For j = 1 To 5
                r = r + Combin8(k, brr(i, j))
            Next
            If r = 5 Then crr(k, i) = i: cnt = cnt + 1
        Next
        crr(k, 1) = cnt
    Next
    With Sheet2
        .[a1].CurrentRegion.AutoFilter
        .[a1].CurrentRegion.Offset(1, 9) = ""
        .[k2].Resize(Ac8, m) = crr
        .Cells(1, 10) = "result"
        .Cells(1, 11) = "cnt"
        For i = 2 To m
            .Cells(1, i + 10) = "s" & i
        Next
    End With
   
    ReDim drr(1 To Ac8, 0 To 1)
    For i = 1 To Ac8
        drr(i, 1) = 1
    Next
   
    ReDim frr(2 To m) As Boolean
    Randomize
    h = m - 1
    k = 0
    Do
        cnt = 1
        For i = 1 To Ac8
            If drr(i, 1) > 0 Then
                r = 0
                For j = 2 To m
                    If Not frr(j) Then If crr(i, j) Then r = r + 1
                Next
                If r Then drr(i, 1) = r Else drr(i, 1) = ""
                If r = cnt Then s = s & "," & i Else If r > cnt Then cnt = r: s = i
            End If
        Next
        
        t = Split(s, ",")
        r = t(Int(Rnd * (UBound(t) + 1)))
        
        cnt = 0
        For j = 2 To m
            If Not frr(j) Then If crr(r, j) Then frr(j) = True: cnt = cnt + 1
        Next
        drr(r, 0) = cnt
        drr(r, 1) = ""
        h = h - cnt
        k = k + 1
    Loop While h
    With Sheet2
        .[j2].Resize(Ac8) = drr
        .[a1].AutoFilter Field:=10, Criteria1:="<>"
        .[i1].Resize(Ac8, 3).SpecialCells(xlCellTypeVisible).Copy
    End With
'    Sheet1.Activate
    Sheet1.[j1].CurrentRegion = ""
    Sheet1.[j1].PasteSpecial Paste:=xlPasteValues
   
    MsgBox Format(Timer - tms, "0.000s ") & k
End Sub
Sub GetCombinArr(arr&(), m&, n&)
    Dim i&, j&, l&
    ReDim a&(1 To n)
    a(1) = 0: a(n) = m: j = 1
    For i = 1 To (m, n)
        If a(n) = m Then
            a(j) = a(j) + 1
            If a(j) < m - n + j Then
                For j = j To n - 1
                    a(j + 1) = a(j) + 1
                Next
            End If
            j = j - 1
        Else
            a(n) = a(n) + 1
        End If
        For l = 1 To n
            arr(i, a(l)) = 1
        Next
    Next
End Sub
模块2--------------------------------------------------------模块2
Sub Macro2()
    Range("I1:K166").SpecialCells(xlCellTypeVisible).Copy
    Selection.PasteSpecial Paste:=xlPasteValues
   
End Sub
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 2013/5/22 by NWP18
'

'
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
End Sub

[ 本帖最后由 warosng 于 2013-10-6 20:28 编辑 ]
2013-10-06 20:08
别小看菜鸟
Rank: 1
等 级:新手上路
帖 子:8
专家分:7
注 册:2013-10-19
收藏
得分:0 
这是段什么程序啊?
2013-10-20 11:04
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
这个是 EXCLE 的VBA 代码。
很多命令没用过。

Sub DataSplit()
    m = Sheet1.[a1].End(4).Row                ‘取a1这个单元格,向下最后一个数据的行号
    arr = Sheet1.[c1].Resize(m, 5)              ‘从C1开始到最后一行,从C1开始向后点5列,生成一个2维数组。真没用过这个命令,测试才看懂
    ReDim brr(2 To m, 1 To 11)
    For i = 2 To m
        For j = 1 To 5
            t = arr(i, j)
            brr(i, t) = t
        Next
    Next
    Sheet1.[h2].Resize(m - 1, 11) = brr            ‘把生成的数据写到 从h2 开始的一个区域时,一共有m-1行,11列。没用过
End Sub

单步测试,看变量的值就大体上能知道是怎么回事了。

授人于鱼,不如授人于渔
早已停用QQ了
2013-10-20 13:27
vbvcr51
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:18
帖 子:364
专家分:1724
注 册:2013-11-3
收藏
得分:0 
VBA就是excel中用这些代码可以控制excel的一些操作。跟vb语言有些相同,但不完全相同的。可以找这方面的书籍。
2013-11-04 21:26
快速回复:•新手,求问VB6的编程问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.052522 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved