使用字典和排序计算行列.bas 732 B

1234567891011121314151617181920212223242526
  1. Private Type Coordinate
  2. x As Double
  3. y As Double
  4. End Type
  5. Sub 计算行列() ' 字典使用计算行列
  6. ActiveDocument.Unit = cdrMillimeter
  7. Set xdict = CreateObject("Scripting.dictionary")
  8. Set ydict = CreateObject("Scripting.dictionary")
  9. Dim dot As Coordinate
  10. Dim s As Shape, ssr As ShapeRange
  11. Set ssr = ActiveSelectionRange
  12. ssr.Sort " @shape1.Top * 100 - @shape1.Left > @shape2.Top * 100 - @shape2.Left"
  13. For Each s In ssr
  14. dot.x = s.CenterX: dot.y = s.CenterY
  15. If xdict.Exists(Int(dot.x)) = False Then xdict.Add Int(dot.x), dot.x
  16. If ydict.Exists(Int(dot.y)) = False Then ydict.Add Int(dot.y), dot.y
  17. Next s
  18. MsgBox "字典使用计算行列:" & xdict.Count & ydict.Count
  19. End Sub