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">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
10 REM -----------------------------------------------------------------------------------------------------------------------
11 Public Function AddItem(Optional pvBox As Variant, ByVal Optional pvItem As Variant, ByVal Optional pvIndex) As Boolean
12 ' Add an item in a Listbox
14 Utils._SetCalledSub(
"AddItem
")
15 If _ErrorHandler() Then On Local Error Goto Error_Function
17 If IsMissing(pvBox) Or IsMissing(pvItem) Then Call _TraceArguments()
18 If IsMissing(pvIndex) Then pvIndex = -
1
19 If Not Utils._CheckArgument(pvBox,
1, Array(CTLLISTBOX, CTLCOMBOBOX)) Then Goto Exit_Function
21 AddItem = pvBox.AddItem(pvItem, pvIndex)
24 Utils._ResetCalledSub(
"AddItem
")
27 TraceError(TRACEABORT, Err,
"AddItem
", Erl)
30 End Function
' AddItem V0.9
.0
32 REM -----------------------------------------------------------------------------------------------------------------------
33 Public Function hasProperty(Optional pvObject As Variant, ByVal Optional pvProperty As Variant) As Boolean
34 ' Return True if pvObject has a valid property called pvProperty (case-insensitive comparison !)
36 Dim vPropertiesList As Variant
38 Utils._SetCalledSub(
"hasProperty
")
39 If IsMissing(pvObject) Or IsMissing(pvProperty) Then Call _TraceArguments()
42 If Not Utils._CheckArgument(pvObject,
1, Array(OBJCOLLECTION, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP, OBJEVENT _
43 , OBJPROPERTY, OBJDATABASE, OBJQUERYDEF, OBJTABLEDEF, OBJRECORDSET _
44 )) Then Goto Exit_Function
45 If Not Utils._CheckArgument(pvProperty,
2, vbString) Then Goto Exit_Function
47 hasProperty = pvObject.hasProperty(pvProperty)
50 Utils._ResetCalledSub(
"hasProperty
")
52 End Function
' hasProperty V0.9
.0
54 REM -----------------------------------------------------------------------------------------------------------------------
55 Public Function Move(Optional pvObject As Object _
56 , ByVal Optional pvLeft As Variant _
57 , ByVal Optional pvTop As Variant _
58 , ByVal Optional pvWidth As Variant _
59 , ByVal Optional pvHeight As Variant _
61 ' Execute Move method
62 Utils._SetCalledSub(
"Move
")
63 If IsMissing(pvObject) Then Call _TraceArguments()
64 If _ErrorHandler() Then On Local Error Goto Error_Function
66 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJDIALOG)) Then Goto Exit_Function
67 If IsMissing(pvLeft) Then Call _TraceArguments()
68 If IsMissing(pvTop) Then pvTop = -
1
69 If IsMissing(pvWidth) Then pvWidth = -
1
70 If IsMissing(pvHeight) Then pvHeight = -
1
72 Move = pvObject.Move(pvLeft, pvTop, pvWidth, pvHeight)
75 Utils._ResetCalledSub(
"Move
")
78 TraceError(TRACEABORT, Err,
"Move
", Erl)
80 End Function
' Move V
.0.9.1
82 REM -----------------------------------------------------------------------------------------------------------------------
83 Public Function OpenHelpFile()
84 ' Open the help file from the Help menu (IDE only)
85 Const cstHelpFile =
"http://www.access2base.com/access2base.html
"
87 On Local Error Resume Next
88 Call _ShellExecute(cstHelpFile)
90 End Function
' OpenHelpFile V0.8
.5
92 REM -----------------------------------------------------------------------------------------------------------------------
93 Public Function Properties(Optional pvObject As Variant, ByVal Optional pvIndex As Variant) As Variant
95 ' a Collection object if pvIndex absent
96 ' a Property object otherwise
98 Dim vProperties As Variant, oCounter As Variant, opProperty As Variant
99 Dim vPropertiesList() As Variant
101 If IsMissing(pvObject) Or IsEmpty(pvObject) Then Call _TraceArguments()
102 Utils._SetCalledSub(
"Properties
")
104 Set vProperties = Nothing
105 If Not Utils._CheckArgument(pvObject,
1, Array(OBJCOLLECTION, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP, OBJEVENT _
106 , OBJPROPERTY, OBJDATABASE, OBJQUERYDEF, OBJTABLEDEF, OBJRECORDSET _
107 )) Then Goto Exit_Function
109 If IsMissing(pvIndex) Then vProperties = pvObject.Properties Else vProperties = pvObject.Properties(pvIndex)
112 Set Properties = vProperties
113 Utils._ResetCalledSub(
"Properties
")
115 End Function
' Properties V0.9
.0
117 REM -----------------------------------------------------------------------------------------------------------------------
118 Public Function Refresh(Optional pvObject As Variant) As Boolean
119 ' Refresh data with its most recent value in the database in a form or subform
120 Utils._SetCalledSub(
"Refresh
")
121 If IsMissing(pvObject) Then Call _TraceArguments()
122 If _ErrorHandler() Then On Local Error Goto Error_Function
124 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJSUBFORM)) Then Goto Exit_Function
126 Refresh = pvObject.Refresh()
129 Utils._ResetCalledSub(
"Refresh
")
132 TraceError(TRACEABORT, Err,
"Refresh
", Erl)
134 End Function
' Refresh V0.9
.0
136 REM -----------------------------------------------------------------------------------------------------------------------
137 Public Function RemoveItem(Optional pvBox As Variant,ByVal Optional pvIndex) As Boolean
138 ' Remove an item from a Listbox
139 ' Index may be a string value or an index-position
141 Utils._SetCalledSub(
"RemoveItem
")
142 If _ErrorHandler() Then On Local Error Goto Error_Function
144 If IsMissing(pvBox) Or IsMissing(pvIndex) Then Call _TraceArguments()
145 If Not Utils._CheckArgument(pvBox,
1, Array(CTLLISTBOX, CTLCOMBOBOX)) Then Goto Exit_Function
147 RemoveItem = pvBox.RemoveItem(pvIndex)
150 Utils._ResetCalledSub(
"RemoveItem
")
153 TraceError(TRACEABORT, Err,
"RemoveItem
", Erl)
156 End Function
' RemoveItem V0.9
.0
158 REM -----------------------------------------------------------------------------------------------------------------------
159 Public Function Requery(Optional pvObject As Variant) As Boolean
160 ' Refresh data displayed in a form, subform, combobox or listbox
161 Utils._SetCalledSub(
"Requery
")
162 If IsMissing(pvObject) Then Call _TraceArguments()
163 If _ErrorHandler() Then On Local Error Goto Error_Function
164 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJCONTROL, OBJSUBFORM)) Then Goto Exit_Function
166 Requery = pvObject.Requery()
169 Utils._ResetCalledSub(
"Requery
")
172 TraceError(TRACEABORT, Err,
"Requery
", Erl)
174 End Function
' Requery V0.9
.0
176 REM -----------------------------------------------------------------------------------------------------------------------
177 Public Function SetFocus(Optional pvObject As Variant) As Boolean
178 ' Execute SetFocus method
179 Utils._SetCalledSub(
"setFocus
")
180 If IsMissing(pvObject) Then Call _TraceArguments()
181 If _ErrorHandler() Then On Local Error Goto Error_Function
182 If Not Utils._CheckArgument(pvObject,
1, Array(OBJFORM, OBJCONTROL)) Then Goto Exit_Function
184 SetFocus = pvObject.setFocus()
187 Utils._ResetCalledSub(
"SetFocus
")
190 TraceError(TRACEABORT, Err,
"SetFocus
", Erl)
193 TraceError(TRACEFATAL, ERRFOCUSINGRID, Utils._CalledSub(),
0,
1, Array(pvObject._Name, ocGrid._Name))
195 End Function
' SetFocus V0.9
.0
197 REM -----------------------------------------------------------------------------------------------------------------------
198 REM --- PRIVATE FUNCTIONS ---
199 REM -----------------------------------------------------------------------------------------------------------------------
200 Public Function _OptionGroup(ByVal pvGroupName As Variant _
201 , ByVal psParentType As String _
202 , poComponent As Object _
203 , poDatabaseForm As Object _
205 ' Return either an error or an object of type OPTIONGROUP based on its name
207 If IsMissing(pvGroupName) Then Call _TraceArguments()
208 If _ErrorHandler() Then On Local Error Goto Error_Function
209 Set _OptionGroup = Nothing
211 If Not Utils._CheckArgument(pvGroupName,
1, vbString) Then Goto Exit_Function
213 Dim ogGroup As Variant, i As Integer, j As Integer, bFound As Boolean
214 Dim vOptionButtons() As Variant, sGroupName As String
215 Dim lXY() As Long, iIndex() As Integer
' Two indexes X-Y coordinates
218 Const cstPixels =
10 ' Tolerance on coordinates when drawed approximately
220 For i =
0 To poDatabaseForm.GroupCount -
1 ' Does a group with the right name exist ?
221 poDatabaseForm.getGroup(i, vOptionButtons, sGroupName)
222 If UCase(sGroupName) = UCase(Utils._Trim(pvGroupName)) Then
229 ogGroup = New Optiongroup
230 ogGroup._Name = sGroupName
231 ogGroup._ButtonsGroup = vOptionButtons
232 ogGroup._Count = UBound(vOptionButtons) +
1
233 ogGroup._ParentType = psParentType
234 Set ogGroup._ParentComponent = poComponent
236 ReDim lXY(
1, ogGroup._Count -
1)
237 ReDim iIndex(ogGroup._Count -
1)
238 For i =
0 To ogGroup._Count -
1 ' Find the position of each radiobutton
239 Set oView = poComponent.CurrentController.getControl(ogGroup._ButtonsGroup(i))
240 lXY(
0, i) = oView.PosSize.X
241 lXY(
1, i) = oView.PosSize.Y
243 For i =
0 To ogGroup._Count -
1 ' Sort them on XY coordinates
248 For j = i -
1 To
0 Step -
1
249 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
250 iIndex(i) = iIndex(j)
251 iIndex(j) = iIndex(j) +
1
256 ogGroup._ButtonsIndex = iIndex()
258 Set _OptionGroup = ogGroup
262 Set _OptionGroup = Nothing
263 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0, , Array(
1, pvGroupName))
270 TraceError(TRACEABORT, Err,
"_OptionGroup
", Erl)
272 End Function
' _OptionGroup V1.1
.0