设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1283|回复: 6
打印 上一主题 下一主题

[模块/函数] 请教如何将组合数字全部列出的问题!

[复制链接]
1#
发表于 2023-2-20 04:51:22 | 显示全部楼层
sxgaobo 发表于 2023-2-19 17:53
这是ChatGPT给的代码:
Public Sub ListCombinations(n As Integer, m As Integer)
    Dim a() As Integ ...

修改如下:
  1. Public Sub ListCombinations(n As Integer, m As Integer)
  2.     Dim a() As Variant
  3.     ReDim a(1 To m)
  4.     Combination 1, n, a, 1, m
  5. End Sub
  6. Private Sub Combination(t As Integer, n As Integer, a() As Variant, k As Integer, m As Integer)
  7.     Dim i As Integer
  8.     If k > m Then
  9.         Debug.Print Join(a, " ")
  10.         Exit Sub
  11.     End If
  12.     For i = t To n
  13.         a(k) = i
  14.         Combination i + 1, n, a, k + 1, m
  15.     Next i
  16. End Sub


  17. Sub test()
  18.     ListCombinations 5, 3
  19. End Sub
复制代码
数组类型应该指定为变型,而不是整型。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-8 10:44 , Processed in 0.115873 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表