API.bas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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("请输入间隔宽度值 0 --> 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. Private test_ArraySort()
  91. Dim arr As Variant, i As Integer
  92. arr = Array(5, 4, 3, 2, 1, 9, 999, 33)
  93. For i = 0 To arrlen(arr) - 1
  94. Debug.Print arr(i);
  95. Next i
  96. Debug.Print arrlen(arr)
  97. ArraySort arr
  98. For i = 0 To arrlen(arr) - 1
  99. Debug.Print arr(i);
  100. Next i
  101. End Sub
  102. Function FindAllShapes() As ShapeRange
  103. Dim s As Shape
  104. Dim srPowerClipped As New ShapeRange
  105. Dim sr As ShapeRange, srAll As New ShapeRange
  106. If ActiveSelection.Shapes.Count > 0 Then
  107. Set sr = ActiveSelection.Shapes.FindShapes()
  108. Else
  109. Set sr = ActivePage.Shapes.FindShapes()
  110. End If
  111. Do
  112. For Each s In sr.Shapes.FindShapes(Query:="[email protected]")
  113. srPowerClipped.AddRange s.PowerClip.Shapes.FindShapes()
  114. Next s
  115. srAll.AddRange sr
  116. sr.RemoveAll
  117. sr.AddRange srPowerClipped
  118. srPowerClipped.RemoveAll
  119. Loop Until sr.Count = 0
  120. Set FindAllShapes = srAll
  121. End Function
  122. ' ************* 函数模块 ************* '
  123. Function ExistsFile_UseFso(ByVal strPath As String) As Boolean
  124. Dim fso
  125. Set fso = CreateObject("Scripting.FileSystemObject")
  126. ExistsFile_UseFso = fso.FileExists(strPath)
  127. Set fso = Nothing
  128. End Function
  129. Function test()
  130. Dim message, sapi
  131. MsgBox ("Please use the headset and listen to what I have to say...")
  132. message = "This is a simple voice test on your Microsoft Windows."
  133. Set sapi = CreateObject("sapi.spvoice")
  134. sapi.Speak message
  135. End Function