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 =======================================================================================================================
11 REM -----------------------------------------------------------------------------------------------------------------------
12 Public Function AddItem(Optional pvBox As Variant, ByVal Optional pvItem As Variant, ByVal Optional pvIndex) As Boolean
13 ' Add an item in a Listbox
15 Utils._SetCalledSub(
"AddItem
")
16 If _ErrorHandler() Then On Local Error Goto Error_Function
18 If IsMissing(pvBox) Or IsMissing(pvItem) Then Call _TraceArguments()
19 If IsMissing(pvIndex) Then pvIndex = -
1
20 If Not Utils._CheckArgument(pvBox,
1, Array(CTLLISTBOX, CTLCOMBOBOX)) Then Goto Exit_Function
22 AddItem = pvBox.AddItem(pvItem, pvIndex)
25 Utils._ResetCalledSub(
"AddItem
")
28 TraceError(TRACEABORT, Err,
"AddItem
", Erl)
31 End Function
' AddItem V0.9
.0
33 REM -----------------------------------------------------------------------------------------------------------------------
34 Public Function hasProperty(Optional pvObject As Variant, ByVal Optional pvProperty As Variant) As Boolean
35 ' Return True if pvObject has a valid property called pvProperty (case-insensitive comparison !)
37 Dim vPropertiesList As Variant
39 Utils._SetCalledSub(
"hasProperty
")
40 If IsMissing(pvObject) Or IsMissing(pvProperty) Then Call _TraceArguments()
43 If Not Utils._CheckArgument(pvObject,
1, Array(OBJCOLLECTION, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP, OBJEVENT _
44 , OBJPROPERTY, OBJDATABASE, OBJQUERYDEF, OBJTABLEDEF, OBJRECORDSET _
45 )) Then Goto Exit_Function
46 If Not Utils._CheckArgument(pvProperty,
2, vbString) Then Goto Exit_Function
48 hasProperty = pvObject.hasProperty(pvProperty)
51 Utils._ResetCalledSub(
"hasProperty
")
53 End Function
' hasProperty V0.9
.0
55 REM -----------------------------------------------------------------------------------------------------------------------
56 Public Function Move(Optional pvObject As Object _
57 , ByVal Optional pvLeft As Variant _
58 , ByVal Optional pvTop As Variant _
59 , ByVal Optional pvWidth As Variant _
60 , ByVal Optional pvHeight As Variant _
62 ' Execute Move method
63 Utils._SetCalledSub(
"Move
")
64 If IsMissing(pvObject) Then Call _TraceArguments()
65 If _ErrorHandler() Then On Local Error Goto Error_Function
67 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJDIALOG)) Then Goto Exit_Function
68 If IsMissing(pvLeft) Then Call _TraceArguments()
69 If IsMissing(pvTop) Then pvTop = -
1
70 If IsMissing(pvWidth) Then pvWidth = -
1
71 If IsMissing(pvHeight) Then pvHeight = -
1
73 Move = pvObject.Move(pvLeft, pvTop, pvWidth, pvHeight)
76 Utils._ResetCalledSub(
"Move
")
79 TraceError(TRACEABORT, Err,
"Move
", Erl)
81 End Function
' Move V
.0.9.1
83 REM -----------------------------------------------------------------------------------------------------------------------
84 Public Function OpenHelpFile()
85 ' Open the help file from the Help menu (IDE only)
86 Const cstHelpFile =
"http://www.access2base.com/access2base.html
"
88 On Local Error Resume Next
89 Call _ShellExecute(cstHelpFile)
91 End Function
' OpenHelpFile V0.8
.5
93 REM -----------------------------------------------------------------------------------------------------------------------
94 Public Function Properties(Optional pvObject As Variant, ByVal Optional pvIndex As Variant) As Variant
96 ' a Collection object if pvIndex absent
97 ' a Property object otherwise
99 Dim vProperties As Variant, oCounter As Variant, opProperty As Variant
100 Dim vPropertiesList() As Variant
102 If IsMissing(pvObject) Or IsEmpty(pvObject) Then Call _TraceArguments()
103 Utils._SetCalledSub(
"Properties
")
105 Set vProperties = Nothing
106 If Not Utils._CheckArgument(pvObject,
1, Array(OBJCOLLECTION, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP, OBJEVENT _
107 , OBJPROPERTY, OBJDATABASE, OBJQUERYDEF, OBJTABLEDEF, OBJRECORDSET _
108 )) Then Goto Exit_Function
110 If IsMissing(pvIndex) Then vProperties = pvObject.Properties Else vProperties = pvObject.Properties(pvIndex)
113 Set Properties = vProperties
114 Utils._ResetCalledSub(
"Properties
")
116 End Function
' Properties V0.9
.0
118 REM -----------------------------------------------------------------------------------------------------------------------
119 Public Function Refresh(Optional pvObject As Variant) As Boolean
120 ' Refresh data with its most recent value in the database in a form or subform
121 Utils._SetCalledSub(
"Refresh
")
122 If IsMissing(pvObject) Then Call _TraceArguments()
123 If _ErrorHandler() Then On Local Error Goto Error_Function
125 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJSUBFORM)) Then Goto Exit_Function
127 Refresh = pvObject.Refresh()
130 Utils._ResetCalledSub(
"Refresh
")
133 TraceError(TRACEABORT, Err,
"Refresh
", Erl)
135 End Function
' Refresh V0.9
.0
137 REM -----------------------------------------------------------------------------------------------------------------------
138 Public Function RemoveItem(Optional pvBox As Variant,ByVal Optional pvIndex) As Boolean
139 ' Remove an item from a Listbox
140 ' Index may be a string value or an index-position
142 Utils._SetCalledSub(
"RemoveItem
")
143 If _ErrorHandler() Then On Local Error Goto Error_Function
145 If IsMissing(pvBox) Or IsMissing(pvIndex) Then Call _TraceArguments()
146 If Not Utils._CheckArgument(pvBox,
1, Array(CTLLISTBOX, CTLCOMBOBOX)) Then Goto Exit_Function
148 RemoveItem = pvBox.RemoveItem(pvIndex)
151 Utils._ResetCalledSub(
"RemoveItem
")
154 TraceError(TRACEABORT, Err,
"RemoveItem
", Erl)
157 End Function
' RemoveItem V0.9
.0
159 REM -----------------------------------------------------------------------------------------------------------------------
160 Public Function Requery(Optional pvObject As Variant) As Boolean
161 ' Refresh data displayed in a form, subform, combobox or listbox
162 Utils._SetCalledSub(
"Requery
")
163 If IsMissing(pvObject) Then Call _TraceArguments()
164 If _ErrorHandler() Then On Local Error Goto Error_Function
165 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJCONTROL, OBJSUBFORM)) Then Goto Exit_Function
167 Requery = pvObject.Requery()
170 Utils._ResetCalledSub(
"Requery
")
173 TraceError(TRACEABORT, Err,
"Requery
", Erl)
175 End Function
' Requery V0.9
.0
177 REM -----------------------------------------------------------------------------------------------------------------------
178 Public Function SetFocus(Optional pvObject As Variant) As Boolean
179 ' Execute SetFocus method
180 Utils._SetCalledSub(
"setFocus
")
181 If IsMissing(pvObject) Then Call _TraceArguments()
182 If _ErrorHandler() Then On Local Error Goto Error_Function
183 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJCONTROL)) Then Goto Exit_Function
185 SetFocus = pvObject.setFocus()
188 Utils._ResetCalledSub(
"SetFocus
")
191 TraceError(TRACEABORT, Err,
"SetFocus
", Erl)
194 TraceError(TRACEFATAL, ERRFOCUSINGRID, Utils._CalledSub(),
0,
1, Array(pvObject._Name, ocGrid._Name))
196 End Function
' SetFocus V0.9
.0
198 REM -----------------------------------------------------------------------------------------------------------------------
199 REM --- PRIVATE FUNCTIONS ---
200 REM -----------------------------------------------------------------------------------------------------------------------
201 Public Function _OptionGroup(ByVal pvGroupName As Variant _
202 , ByVal psParentType As String _
203 , poComponent As Object _
204 , poParent As Object _
206 ' Return either an error or an object of type OPTIONGROUP based on its name
208 If IsMissing(pvGroupName) Then Call _TraceArguments()
209 If _ErrorHandler() Then On Local Error Goto Error_Function
210 Set _OptionGroup = Nothing
212 If Not Utils._CheckArgument(pvGroupName,
1, vbString) Then Goto Exit_Function
214 Dim ogGroup As Variant, i As Integer, j As Integer, bFound As Boolean
215 Dim vOptionButtons() As Variant, sGroupName As String
216 Dim lXY() As Long, iIndex() As Integer
' Two indexes X-Y coordinates
217 Dim oView As Object, oDatabaseForm As Object, vControls As Variant
219 Const cstPixels =
10 ' Tolerance on coordinates when drawn approximately
222 Select Case psParentType
224 'poParent is a forms collection, find the appropriate database form
225 For i =
0 To poParent.Count -
1
226 Set oDatabaseForm = poParent.getByIndex(i)
227 If Not IsNull(oDatabaseForm) Then
228 For j =
0 To oDatabaseForm.GroupCount -
1 ' Does a group with the right name exist ?
229 oDatabaseForm.getGroup(j, vOptionButtons, sGroupName)
230 If UCase(sGroupName) = UCase(Utils._Trim(pvGroupName)) Then
235 If bFound Then Exit For
237 If bFound Then Exit For
239 Case CTLPARENTISSUBFORM
240 'poParent is already a database form
241 Set oDatabaseForm = poParent
242 For j =
0 To oDatabaseForm.GroupCount -
1 ' Does a group with the right name exist ?
243 oDatabaseForm.getGroup(j, vOptionButtons, sGroupName)
244 If UCase(sGroupName) = UCase(Utils._Trim(pvGroupName)) Then
253 ogGroup = New Optiongroup
254 ogGroup._This = ogGroup
255 ogGroup._Name = sGroupName
256 ogGroup._ButtonsGroup = vOptionButtons
257 ogGroup._Count = UBound(vOptionButtons) +
1
258 ogGroup._ParentType = psParentType
259 ogGroup._MainForm = oDatabaseForm.Name
260 Set ogGroup._ParentComponent = poComponent
262 ReDim lXY(
1, ogGroup._Count -
1)
263 ReDim iIndex(ogGroup._Count -
1)
264 For i =
0 To ogGroup._Count -
1 ' Find the position of each radiobutton
265 Set oView = poComponent.CurrentController.getControl(ogGroup._ButtonsGroup(i))
266 lXY(
0, i) = oView.PosSize.X
267 lXY(
1, i) = oView.PosSize.Y
269 For i =
0 To ogGroup._Count -
1 ' Sort them on XY coordinates
274 For j = i -
1 To
0 Step -
1
275 If lXY(
1, i) - lXY(
1, j)
< - cstPixels Or ( Abs(lXY(
1, i) - lXY(
1, j))
<= cstPixels And lXY(
0, i) - lXY(
0, j)
< - cstPixels ) Then
276 iIndex(i) = iIndex(j)
277 iIndex(j) = iIndex(j) +
1
282 ogGroup._ButtonsIndex = iIndex()
284 Set _OptionGroup = ogGroup
288 Set _OptionGroup = Nothing
289 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvGroupName))
296 TraceError(TRACEABORT, Err,
"_OptionGroup
", Erl)
298 End Function
' _OptionGroup V1.1
.0