Methods.xba 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Methods" script:language="StarBasic">
  4. REM =======================================================================================================================
  5. REM === The Access2Base library is a part of the LibreOffice project. ===
  6. REM === Full documentation is available on http://www.access2base.com ===
  7. REM =======================================================================================================================
  8. Option Explicit
  9. REM -----------------------------------------------------------------------------------------------------------------------
  10. Public Function AddItem(Optional pvBox As Variant, ByVal Optional pvItem As Variant, ByVal Optional pvIndex) As Boolean
  11. &apos; Add an item in a Listbox
  12. Utils._SetCalledSub(&quot;AddItem&quot;)
  13. If _ErrorHandler() Then On Local Error Goto Error_Function
  14. If IsMissing(pvBox) Or IsMissing(pvItem) Then Call _TraceArguments()
  15. If IsMissing(pvIndex) Then pvIndex = -1
  16. If Not Utils._CheckArgument(pvBox, 1, Array(CTLLISTBOX, CTLCOMBOBOX)) Then Goto Exit_Function
  17. AddItem = pvBox.AddItem(pvItem, pvIndex)
  18. Exit_Function:
  19. Utils._ResetCalledSub(&quot;AddItem&quot;)
  20. Exit Function
  21. Error_Function:
  22. TraceError(TRACEABORT, Err, &quot;AddItem&quot;, Erl)
  23. AddItem = False
  24. GoTo Exit_Function
  25. End Function &apos; AddItem V0.9.0
  26. REM -----------------------------------------------------------------------------------------------------------------------
  27. Public Function hasProperty(Optional pvObject As Variant, ByVal Optional pvProperty As Variant) As Boolean
  28. &apos; Return True if pvObject has a valid property called pvProperty (case-insensitive comparison !)
  29. Dim vPropertiesList As Variant
  30. Utils._SetCalledSub(&quot;hasProperty&quot;)
  31. If IsMissing(pvObject) Or IsMissing(pvProperty) Then Call _TraceArguments()
  32. hasProperty = False
  33. If Not Utils._CheckArgument(pvObject, 1, Array(OBJCOLLECTION, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP, OBJEVENT _
  34. , OBJPROPERTY, OBJDATABASE, OBJQUERYDEF, OBJTABLEDEF, OBJRECORDSET _
  35. )) Then Goto Exit_Function
  36. If Not Utils._CheckArgument(pvProperty, 2, vbString) Then Goto Exit_Function
  37. hasProperty = pvObject.hasProperty(pvProperty)
  38. Exit_Function:
  39. Utils._ResetCalledSub(&quot;hasProperty&quot;)
  40. Exit Function
  41. End Function &apos; hasProperty V0.9.0
  42. REM -----------------------------------------------------------------------------------------------------------------------
  43. Public Function Move(Optional pvObject As Object _
  44. , ByVal Optional pvLeft As Variant _
  45. , ByVal Optional pvTop As Variant _
  46. , ByVal Optional pvWidth As Variant _
  47. , ByVal Optional pvHeight As Variant _
  48. ) As Variant
  49. &apos; Execute Move method
  50. Utils._SetCalledSub(&quot;Move&quot;)
  51. If IsMissing(pvObject) Then Call _TraceArguments()
  52. If _ErrorHandler() Then On Local Error Goto Error_Function
  53. Move = False
  54. If Not Utils._CheckArgument(pvObject, 1, Array(OBJFORM, OBJDIALOG)) Then Goto Exit_Function
  55. If IsMissing(pvLeft) Then Call _TraceArguments()
  56. If IsMissing(pvTop) Then pvTop = -1
  57. If IsMissing(pvWidth) Then pvWidth = -1
  58. If IsMissing(pvHeight) Then pvHeight = -1
  59. Move = pvObject.Move(pvLeft, pvTop, pvWidth, pvHeight)
  60. Exit_Function:
  61. Utils._ResetCalledSub(&quot;Move&quot;)
  62. Exit Function
  63. Error_Function:
  64. TraceError(TRACEABORT, Err, &quot;Move&quot;, Erl)
  65. GoTo Exit_Function
  66. End Function &apos; Move V.0.9.1
  67. REM -----------------------------------------------------------------------------------------------------------------------
  68. Public Function OpenHelpFile()
  69. &apos; Open the help file from the Help menu (IDE only)
  70. Const cstHelpFile = &quot;http://www.access2base.com/access2base.html&quot;
  71. On Local Error Resume Next
  72. Call _ShellExecute(cstHelpFile)
  73. End Function &apos; OpenHelpFile V0.8.5
  74. REM -----------------------------------------------------------------------------------------------------------------------
  75. Public Function Properties(Optional pvObject As Variant, ByVal Optional pvIndex As Variant) As Variant
  76. &apos; Return
  77. &apos; a Collection object if pvIndex absent
  78. &apos; a Property object otherwise
  79. Dim vProperties As Variant, oCounter As Variant, opProperty As Variant
  80. Dim vPropertiesList() As Variant
  81. If IsMissing(pvObject) Or IsEmpty(pvObject) Then Call _TraceArguments()
  82. Utils._SetCalledSub(&quot;Properties&quot;)
  83. Set vProperties = Nothing
  84. If Not Utils._CheckArgument(pvObject, 1, Array(OBJCOLLECTION, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP, OBJEVENT _
  85. , OBJPROPERTY, OBJDATABASE, OBJQUERYDEF, OBJTABLEDEF, OBJRECORDSET _
  86. )) Then Goto Exit_Function
  87. If IsMissing(pvIndex) Then vProperties = pvObject.Properties Else vProperties = pvObject.Properties(pvIndex)
  88. Exit_Function:
  89. Set Properties = vProperties
  90. Utils._ResetCalledSub(&quot;Properties&quot;)
  91. Exit Function
  92. End Function &apos; Properties V0.9.0
  93. REM -----------------------------------------------------------------------------------------------------------------------
  94. Public Function Refresh(Optional pvObject As Variant) As Boolean
  95. &apos; Refresh data with its most recent value in the database in a form or subform
  96. Utils._SetCalledSub(&quot;Refresh&quot;)
  97. If IsMissing(pvObject) Then Call _TraceArguments()
  98. If _ErrorHandler() Then On Local Error Goto Error_Function
  99. Refresh = False
  100. If Not Utils._CheckArgument(pvObject, 1, Array(OBJFORM, OBJSUBFORM)) Then Goto Exit_Function
  101. Refresh = pvObject.Refresh()
  102. Exit_Function:
  103. Utils._ResetCalledSub(&quot;Refresh&quot;)
  104. Exit Function
  105. Error_Function:
  106. TraceError(TRACEABORT, Err, &quot;Refresh&quot;, Erl)
  107. GoTo Exit_Function
  108. End Function &apos; Refresh V0.9.0
  109. REM -----------------------------------------------------------------------------------------------------------------------
  110. Public Function RemoveItem(Optional pvBox As Variant,ByVal Optional pvIndex) As Boolean
  111. &apos; Remove an item from a Listbox
  112. &apos; Index may be a string value or an index-position
  113. Utils._SetCalledSub(&quot;RemoveItem&quot;)
  114. If _ErrorHandler() Then On Local Error Goto Error_Function
  115. If IsMissing(pvBox) Or IsMissing(pvIndex) Then Call _TraceArguments()
  116. If Not Utils._CheckArgument(pvBox, 1, Array(CTLLISTBOX, CTLCOMBOBOX)) Then Goto Exit_Function
  117. RemoveItem = pvBox.RemoveItem(pvIndex)
  118. Exit_Function:
  119. Utils._ResetCalledSub(&quot;RemoveItem&quot;)
  120. Exit Function
  121. Error_Function:
  122. TraceError(TRACEABORT, Err, &quot;RemoveItem&quot;, Erl)
  123. RemoveItem = False
  124. GoTo Exit_Function
  125. End Function &apos; RemoveItem V0.9.0
  126. REM -----------------------------------------------------------------------------------------------------------------------
  127. Public Function Requery(Optional pvObject As Variant) As Boolean
  128. &apos; Refresh data displayed in a form, subform, combobox or listbox
  129. Utils._SetCalledSub(&quot;Requery&quot;)
  130. If IsMissing(pvObject) Then Call _TraceArguments()
  131. If _ErrorHandler() Then On Local Error Goto Error_Function
  132. If Not Utils._CheckArgument(pvObject, 1, Array(OBJFORM, OBJCONTROL, OBJSUBFORM)) Then Goto Exit_Function
  133. Requery = pvObject.Requery()
  134. Exit_Function:
  135. Utils._ResetCalledSub(&quot;Requery&quot;)
  136. Exit Function
  137. Error_Function:
  138. TraceError(TRACEABORT, Err, &quot;Requery&quot;, Erl)
  139. GoTo Exit_Function
  140. End Function &apos; Requery V0.9.0
  141. REM -----------------------------------------------------------------------------------------------------------------------
  142. Public Function SetFocus(Optional pvObject As Variant) As Boolean
  143. &apos; Execute SetFocus method
  144. Utils._SetCalledSub(&quot;setFocus&quot;)
  145. If IsMissing(pvObject) Then Call _TraceArguments()
  146. If _ErrorHandler() Then On Local Error Goto Error_Function
  147. If Not Utils._CheckArgument(pvObject, 1, Array(OBJFORM, OBJCONTROL)) Then Goto Exit_Function
  148. SetFocus = pvObject.setFocus()
  149. Exit_Function:
  150. Utils._ResetCalledSub(&quot;SetFocus&quot;)
  151. Exit Function
  152. Error_Function:
  153. TraceError(TRACEABORT, Err, &quot;SetFocus&quot;, Erl)
  154. Goto Exit_Function
  155. Error_Grid:
  156. TraceError(TRACEFATAL, ERRFOCUSINGRID, Utils._CalledSub(), 0, 1, Array(pvObject._Name, ocGrid._Name))
  157. Goto Exit_Function
  158. End Function &apos; SetFocus V0.9.0
  159. REM -----------------------------------------------------------------------------------------------------------------------
  160. REM --- PRIVATE FUNCTIONS ---
  161. REM -----------------------------------------------------------------------------------------------------------------------
  162. Public Function _OptionGroup(ByVal pvGroupName As Variant _
  163. , ByVal psParentType As String _
  164. , poComponent As Object _
  165. , poParent As Object _
  166. ) As Variant
  167. &apos; Return either an error or an object of type OPTIONGROUP based on its name
  168. If IsMissing(pvGroupName) Then Call _TraceArguments()
  169. If _ErrorHandler() Then On Local Error Goto Error_Function
  170. Set _OptionGroup = Nothing
  171. If Not Utils._CheckArgument(pvGroupName, 1, vbString) Then Goto Exit_Function
  172. Dim ogGroup As Variant, i As Integer, j As Integer, bFound As Boolean
  173. Dim vOptionButtons() As Variant, sGroupName As String
  174. Dim lXY() As Long, iIndex() As Integer &apos; Two indexes X-Y coordinates
  175. Dim oView As Object, oDatabaseForm As Object, vControls As Variant
  176. Const cstPixels = 10 &apos; Tolerance on coordinates when drawn approximately
  177. bFound = False
  178. Select Case psParentType
  179. Case CTLPARENTISFORM
  180. &apos;poParent is a forms collection, find the appropriate database form
  181. For i = 0 To poParent.Count - 1
  182. Set oDatabaseForm = poParent.getByIndex(i)
  183. If Not IsNull(oDatabaseForm) Then
  184. For j = 0 To oDatabaseForm.GroupCount - 1 &apos; Does a group with the right name exist ?
  185. oDatabaseForm.getGroup(j, vOptionButtons, sGroupName)
  186. If UCase(sGroupName) = UCase(Utils._Trim(pvGroupName)) Then
  187. bFound = True
  188. Exit For
  189. End If
  190. Next j
  191. If bFound Then Exit For
  192. End If
  193. If bFound Then Exit For
  194. Next i
  195. Case CTLPARENTISSUBFORM
  196. &apos;poParent is already a database form
  197. Set oDatabaseForm = poParent
  198. For j = 0 To oDatabaseForm.GroupCount - 1 &apos; Does a group with the right name exist ?
  199. oDatabaseForm.getGroup(j, vOptionButtons, sGroupName)
  200. If UCase(sGroupName) = UCase(Utils._Trim(pvGroupName)) Then
  201. bFound = True
  202. Exit For
  203. End If
  204. Next j
  205. End Select
  206. If bFound Then
  207. ogGroup = New Optiongroup
  208. ogGroup._This = ogGroup
  209. ogGroup._Name = sGroupName
  210. ogGroup._ButtonsGroup = vOptionButtons
  211. ogGroup._Count = UBound(vOptionButtons) + 1
  212. ogGroup._ParentType = psParentType
  213. ogGroup._MainForm = oDatabaseForm.Name
  214. Set ogGroup._ParentComponent = poComponent
  215. ReDim lXY(1, ogGroup._Count - 1)
  216. ReDim iIndex(ogGroup._Count - 1)
  217. For i = 0 To ogGroup._Count - 1 &apos; Find the position of each radiobutton
  218. Set oView = poComponent.CurrentController.getControl(ogGroup._ButtonsGroup(i))
  219. lXY(0, i) = oView.PosSize.X
  220. lXY(1, i) = oView.PosSize.Y
  221. Next i
  222. For i = 0 To ogGroup._Count - 1 &apos; Sort them on XY coordinates
  223. If i = 0 Then
  224. iIndex(0) = 0
  225. Else
  226. iIndex(i) = i
  227. For j = i - 1 To 0 Step -1
  228. If lXY(1, i) - lXY(1, j) &lt; - cstPixels Or ( Abs(lXY(1, i) - lXY(1, j)) &lt;= cstPixels And lXY(0, i) - lXY(0, j) &lt; - cstPixels ) Then
  229. iIndex(i) = iIndex(j)
  230. iIndex(j) = iIndex(j) + 1
  231. End If
  232. Next j
  233. End If
  234. Next i
  235. ogGroup._ButtonsIndex = iIndex()
  236. Set _OptionGroup = ogGroup
  237. Else
  238. Set _OptionGroup = Nothing
  239. TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(), 0, , Array(1, pvGroupName))
  240. End If
  241. Exit_Function:
  242. Exit Function
  243. Error_Function:
  244. TraceError(TRACEABORT, Err,&quot;_OptionGroup&quot;, Erl)
  245. GoTo Exit_Function
  246. End Function &apos; _OptionGroup V1.1.0
  247. </script:module>