API.bas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. Attribute VB_Name = "API"
  2. Public Function Speak_Msg(message As String)
  3. Speak_Help = Val(GetSetting("262235.xyz", "Settings", "SpeakHelp", "1"))
  4. If Val(Speak_Help) = 1 Then
  5. Dim sapi
  6. Set sapi = CreateObject("sapi.spvoice")
  7. sapi.Speak message
  8. Else
  9. ' 不说话
  10. End If
  11. End Function
  12. Public Function GetSet(s As String)
  13. Bleed = Val(GetSetting("262235.xyz", "Settings", "Bleed", "2.0"))
  14. Line_len = Val(GetSetting("262235.xyz", "Settings", "Line_len", "3.0"))
  15. Outline_Width = Val(GetSetting("262235.xyz", "Settings", "Outline_Width", "0.2"))
  16. ' Debug.Print Bleed, Line_len, Outline_Width
  17. If s = "Bleed" Then
  18. GetSet = Bleed
  19. ElseIf s = "Line_len" Then
  20. GetSet = Line_len
  21. ElseIf s = "Outline_Width" Then
  22. GetSet = Outline_Width
  23. End If
  24. End Function
  25. Public Function Create_Tolerance() As Double
  26. Dim text As String
  27. If GlobalUserData.Exists("Tolerance", 1) Then
  28. text = GlobalUserData("Tolerance", 1)
  29. End If
  30. text = InputBox("请输入容差值 0.1 --> 9.9", "容差值(mm)", text)
  31. If text = "" Then Exit Function
  32. GlobalUserData("Tolerance", 1) = text
  33. Create_Tolerance = Val(text)
  34. End Function
  35. Public Function Set_Space_Width() As Double
  36. Dim text As String
  37. If GlobalUserData.Exists("SpaceWidth", 1) Then
  38. text = GlobalUserData("SpaceWidth", 1)
  39. End If
  40. text = InputBox("请输入间隔宽度值 -99 --> 99", "设置间隔宽度(mm)", text)
  41. If text = "" Then Exit Function
  42. GlobalUserData("SpaceWidth", 1) = text
  43. Set_Space_Width = Val(text)
  44. End Function
  45. '// 获得剪贴板文本字符
  46. Public Function GetClipBoardString() As String
  47. On Error Resume Next
  48. Dim MyData As New DataObject
  49. GetClipBoardString = ""
  50. MyData.GetFromClipboard
  51. GetClipBoardString = MyData.GetText
  52. Set MyData = Nothing
  53. End Function
  54. '// 文本字符复制到剪贴板
  55. Public Function WriteClipBoard(ByVal s As String)
  56. On Error Resume Next
  57. ' VBA_WIN10(vba7) 使用PutInClipboard乱码解决办法
  58. #If VBA7 Then
  59. With CreateObject("Forms.TextBox.1")
  60. .MultiLine = True
  61. .text = s
  62. .SelStart = 0
  63. .SelLength = .TextLength
  64. .Copy
  65. End With
  66. #Else
  67. Dim MyData As New DataObject
  68. MyData.SetText s
  69. MyData.PutInClipboard
  70. #End If
  71. End Function
  72. '// 获得数组元素个数
  73. Public Function arrlen(src As Variant) As Integer
  74. On Error Resume Next '空意味着 0 长度
  75. arrlen = (UBound(src) - LBound(src))
  76. End Function
  77. '// 对数组进行排序[单维]
  78. Public Function ArraySort(src As Variant) As Variant
  79. Dim out As Long, I As Long, tmp As Variant
  80. For out = LBound(src) To UBound(src) - 1
  81. For I = out + 1 To UBound(src)
  82. If src(out) > src(I) Then
  83. tmp = src(I): src(I) = src(out): src(out) = tmp
  84. End If
  85. Next I
  86. Next out
  87. ArraySort = src
  88. End Function
  89. '// 把一个数组倒序
  90. Public Function ArrayReverse(arr)
  91. Dim I As Integer, n As Integer
  92. n = UBound(arr)
  93. Dim p(): ReDim p(n)
  94. For I = 0 To n
  95. p(I) = arr(n - I)
  96. Next
  97. ArrayReverse = p
  98. End Function
  99. '// 测试数组排序
  100. Private Function test_ArraySort()
  101. Dim arr As Variant, I As Integer
  102. arr = Array(5, 4, 3, 2, 1, 9, 999, 33)
  103. For I = 0 To arrlen(arr) - 1
  104. Debug.Print arr(I);
  105. Next I
  106. Debug.Print arrlen(arr)
  107. ArraySort arr
  108. For I = 0 To arrlen(arr) - 1
  109. Debug.Print arr(I);
  110. Next I
  111. End Function
  112. '// 两点连线的角度:返回角度(相对于X轴的角度)
  113. '// p为末点,O为始点
  114. Public Function alfaPP(p, o)
  115. Dim pi As Double: pi = 4 * Atn(1)
  116. Dim beta As Double
  117. If p(0) = o(0) And p(1) = o(1) Then '二点重合
  118. alfaPP = 0
  119. Exit Function
  120. ElseIf p(0) = o(0) And p(1) > o(1) Then
  121. beta = pi / 2
  122. ElseIf p(0) = o(0) And p(1) < o(1) Then
  123. beta = -pi / 2
  124. ElseIf p(1) = o(1) And p(0) < o(0) Then
  125. beta = pi
  126. ElseIf p(1) = o(1) And p(0) > o(0) Then
  127. beta = 0
  128. Else
  129. beta = Atn((p(1) - o(1)) / VBA.Abs(p(0) - o(0)))
  130. If p(1) > o(1) And p(0) < o(0) Then
  131. beta = pi - beta
  132. ElseIf p(1) < o(1) And p(0) < o(0) Then
  133. beta = -(pi + beta)
  134. End If
  135. End If
  136. alfaPP = beta * 180 / pi
  137. End Function
  138. '// 求过P点到线段AB上的垂足点(XY平面内的二维计算)
  139. Public Function pFootInXY(p, a, B)
  140. If a(0) = B(0) Then
  141. pFootInXY = Array(a(0), p(1), 0#): Exit Function
  142. End If
  143. If a(1) = B(1) Then
  144. pFootInXY = Array(p(0), a(1), 0#): Exit Function
  145. End If
  146. Dim aa, bb, c, d, x, Y
  147. aa = (a(1) - B(1)) / (a(0) - B(0))
  148. bb = a(1) - aa * a(0)
  149. c = -(a(0) - B(0)) / (a(1) - B(1))
  150. d = p(1) - c * p(0)
  151. x = (d - bb) / (aa - c)
  152. Y = aa * x + bb
  153. pFootInXY = Array(x, Y, 0#)
  154. End Function
  155. Function FindAllShapes() As ShapeRange
  156. Dim s As Shape
  157. Dim srPowerClipped As New ShapeRange
  158. Dim sr As ShapeRange, srAll As New ShapeRange
  159. If ActiveSelection.Shapes.Count > 0 Then
  160. Set sr = ActiveSelection.Shapes.FindShapes()
  161. Else
  162. Set sr = ActivePage.Shapes.FindShapes()
  163. End If
  164. Do
  165. For Each s In sr.Shapes.FindShapes(Query:="!@com.powerclip.IsNull")
  166. srPowerClipped.AddRange s.PowerClip.Shapes.FindShapes()
  167. Next s
  168. srAll.AddRange sr
  169. sr.RemoveAll
  170. sr.AddRange srPowerClipped
  171. srPowerClipped.RemoveAll
  172. Loop Until sr.Count = 0
  173. Set FindAllShapes = srAll
  174. End Function
  175. ' ************* 函数模块 ************* '
  176. Function ExistsFile_UseFso(ByVal strPath As String) As Boolean
  177. Dim fso
  178. Set fso = CreateObject("Scripting.FileSystemObject")
  179. ExistsFile_UseFso = fso.FileExists(strPath)
  180. Set fso = Nothing
  181. End Function
  182. Function test()
  183. Dim message, sapi
  184. MsgBox ("Please use the headset and listen to what I have to say...")
  185. message = "This is a simple voice test on your Microsoft Windows."
  186. Set sapi = CreateObject("sapi.spvoice")
  187. sapi.Speak message
  188. End Function