明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: zhengchuan

数字按规律求和

  [复制链接]
 楼主| 发表于 2012-9-23 23:14:40 | 显示全部楼层
xyp1964 发表于 2012-9-23 09:45

差不多吧。反正尽量三相平衡啦。搞电力都明白啦
回复

使用道具 举报

发表于 2012-9-24 13:17:40 | 显示全部楼层
本帖最后由 zml84 于 2012-9-25 13:06 编辑

源码参考:http://zml84.blog.sohu.com/239224434.html

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复

使用道具 举报

发表于 2012-9-24 13:21:56 | 显示全部楼层
用vba行吗?楼主您的问题解决了吗已经?

点评

语言不重要,要的是算法。  发表于 2012-9-24 13:23
回复

使用道具 举报

发表于 2012-9-24 15:06:06 | 显示全部楼层
用vba写的,在我电脑上测试无误:
  1. Sub aa()
  2. Dim arr()
  3. Dim xls As Excel.Application
  4. Set xls = New Excel.Application
  5. Dim s As AcadText
  6. Dim str As String
  7. Dim returnPnt As Variant
  8. Dim ss As AcadSelectionSet
  9. Set ss = ThisDrawing.SelectionSets.Add(Rnd() & "ffdfd")
  10. Dim gpCode(0) As Integer
  11. Dim dataValue(0) As Variant
  12. gpCode(0) = 0
  13. dataValue(0) = "text"
  14. ss.SelectOnScreen gpCode, dataValue
  15. s1 = UCase(InputBox("赋最大值给:"))
  16. s2 = UCase(InputBox("赋第二大值给:"))
  17. s3 = UCase(InputBox("赋第三大值给:"))
  18. For i = 1 To ss.Count
  19. Set s = ss(i - 1)
  20. If IsNumeric(s.TextString) Then
  21. cnt = cnt + 1
  22. ReDim Preserve arr(1 To cnt)
  23. arr(i) = --s.TextString
  24. End If
  25. Next
  26. max1 = xls.Large(arr, 1) + xls.Large(arr, 6)
  27. max2 = xls.Large(arr, 2) + xls.Large(arr, 5)
  28. max3 = xls.Large(arr, 3) + xls.Large(arr, 4)
  29. brr = Array(max1, max2, max3)
  30. On Error Resume Next
  31. For i = 7 To UBound(arr) Step 3
  32. imax1 = 0
  33. imax2 = 0
  34. imax3 = 0
  35.   For j = 1 To 3
  36.     If brr(j - 1) >= max3 Then imax3 = imax3 + 1
  37.     If brr(j - 1) >= max2 Then imax2 = imax2 + 1
  38.     If brr(j - 1) >= max1 Then imax1 = imax1 + 1
  39.   Next
  40. max3 = max3 + xls.Large(arr, 3 - imax3 + i)
  41. max2 = max2 + xls.Large(arr, (3 - imax2) + i)
  42. max1 = max1 + xls.Large(arr, 3 - imax1 + i)
  43. brr = Array(max1, max2, max3)
  44. Next
  45. str = s1 & ":" & max1 & Chr(10) & s2 & ":" & max2 & Chr(10) & s3 & ":" & max3
  46. returnPnt = ThisDrawing.Utility.GetPoint(, "请点击获取插入点")
  47. ThisDrawing.ModelSpace.AddMText returnPnt, 10, str
  48. End Sub
回复

使用道具 举报

发表于 2012-9-24 15:07:27 | 显示全部楼层
传上附件!     

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

点评

结果是怎样的?  发表于 2012-9-24 17:25
回复

使用道具 举报

发表于 2012-9-24 17:59:33 | 显示全部楼层
zml84 发表于 2012-9-24 13:17
源码参考:http://zml84.blog.sohu.com/239224434.html

如附件动画所示:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复

使用道具 举报

发表于 2012-9-24 18:00:54 | 显示全部楼层
33楼代码有点小问题,现传上新代码:
  1. Sub aa()
  2. Dim arr()
  3. Dim xls As Excel.Application
  4. Set xls = New Excel.Application
  5. Dim s As AcadText
  6. Dim str As String
  7. Dim returnPnt As Variant
  8. Dim mt As AcadMText
  9. Dim ss As AcadSelectionSet
  10. Set ss = ThisDrawing.SelectionSets.Add(Rnd() & "ffdfdfd")
  11. Dim gpCode(0) As Integer
  12. Dim dataValue(0) As Variant
  13. gpCode(0) = 0
  14. dataValue(0) = "text"
  15. ss.SelectOnScreen gpCode, dataValue
  16. s1 = UCase(InputBox("赋最大值给:"))
  17. s2 = UCase(InputBox("赋第二大值给:"))
  18. s3 = UCase(InputBox("赋第三大值给:"))
  19. For i = 1 To ss.Count
  20. Set s = ss(i - 1)
  21. If IsNumeric(s.TextString) Then
  22. cnt = cnt + 1
  23. ReDim Preserve arr(1 To cnt)
  24. arr(cnt) = --s.TextString
  25. End If
  26. Next
  27. max1 = xls.Large(arr, 1) + xls.Large(arr, 6)
  28. max2 = xls.Large(arr, 2) + xls.Large(arr, 5)
  29. max3 = xls.Large(arr, 3) + xls.Large(arr, 4)
  30. brr = Array(max1, max2, max3)
  31. On Error Resume Next
  32. For i = 7 To UBound(arr) Step 3
  33. imax1 = 0
  34. imax2 = 0
  35. imax3 = 0
  36.   For j = 1 To 3
  37.     If brr(j - 1) >= max3 Then imax3 = imax3 + 1
  38.     If brr(j - 1) >= max2 Then imax2 = imax2 + 1
  39.     If brr(j - 1) >= max1 Then imax1 = imax1 + 1
  40.   Next
  41. max3 = max3 + xls.Large(arr, 3 - imax3 + i)
  42. max2 = max2 + xls.Large(arr, (3 - imax2) + i)
  43. max1 = max1 + xls.Large(arr, 3 - imax1 + i)
  44. brr = Array(max1, max2, max3)
  45. Next
  46. str = s1 & "的和:" & max1 & Chr(10) & s2 & "的和:" & max2 & Chr(10) & s3 & "的和:" & max3
  47. returnPnt = ThisDrawing.Utility.GetPoint(, "请点击获取插入点")
  48. Set mt = ThisDrawing.ModelSpace.AddMText(returnPnt, 5000, str)
  49. mt.Height = 300



  50. End Sub
回复

使用道具 举报

发表于 2012-9-24 18:01:37 | 显示全部楼层
下面是附件:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复

使用道具 举报

发表于 2012-9-24 18:02:52 | 显示全部楼层
vba要正常运行,要先在vbe编辑器中引用:
工具----引用----microsoft excel object libiray

不知道合不合楼主意,花了我一个中午午休的时间,如果可以的话,楼主的100大洋.......

评分

参与人数 1明经币 +1 收起 理由
革天明 + 1 先加个币吧!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2012-9-24 22:46:17 | 显示全部楼层
本帖最后由 zhengchuan 于 2012-9-24 22:46 编辑

不好意思。这几天在赶份图纸。白天单位上不了网,回家都很晚啦。zml84 兄和sscylh 兄大作都看啦。zml84 兄的程序加载显示输入的列表有缺陷。sscylh兄的满足了一个要求。其实我还需要的是在相别上要标上ABC。光有这ABC的和没用啊。
程序达到目的即可,用哪种语言都无所谓啦。
望二位费费心再给完善下拉。

点评

请测试 31 楼源码。  发表于 2012-9-25 13:07
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-24 09:37 , Processed in 0.160093 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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