xref: /trunk/main/wizards/source/tools/Strings.xba (revision 66b843ff8f1eedd2e69941f1ea52fa080f01ec28)
1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Strings" script:language="StarBasic">Option Explicit
24cdf0e10cSrcweirPublic sProductname as String
25cdf0e10cSrcweir
26cdf0e10cSrcweir
27cdf0e10cSrcweir&apos; Deletes out of a String &apos;BigString&apos; all possible PartStrings, that are summed up
28cdf0e10cSrcweir&apos; in the Array &apos;ElimArray&apos;
29cdf0e10cSrcweirFunction ElimChar(ByVal BigString as String, ElimArray() as String)
30cdf0e10cSrcweirDim i% ,n%
31cdf0e10cSrcweir    For i = 0 to Ubound(ElimArray)
32cdf0e10cSrcweir        BigString = DeleteStr(BigString,ElimArray(i)
33cdf0e10cSrcweir    Next
34cdf0e10cSrcweir    ElimChar = BigString
35cdf0e10cSrcweirEnd Function
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir&apos; Deletes out of a String &apos;BigString&apos; a possible Partstring &apos;CompString&apos;
39cdf0e10cSrcweirFunction DeleteStr(ByVal BigString,CompString as String) as String
40cdf0e10cSrcweirDim i%, CompLen%, BigLen%
41cdf0e10cSrcweir    CompLen = Len(CompString)
42cdf0e10cSrcweir    i = 1
43cdf0e10cSrcweir    While i &lt;&gt; 0
44cdf0e10cSrcweir        i = Instr(i, BigString,CompString)
45cdf0e10cSrcweir        If i &lt;&gt; 0 then
46cdf0e10cSrcweir            BigLen = Len(BigString)
47cdf0e10cSrcweir            BigString = Mid(BigString,1,i-1) + Mid(BigString,i+CompLen,BigLen-i+1-CompLen)
48cdf0e10cSrcweir        End If
49cdf0e10cSrcweir    Wend
50cdf0e10cSrcweir    DeleteStr = BigString
51cdf0e10cSrcweirEnd Function
52cdf0e10cSrcweir
53cdf0e10cSrcweir
54cdf0e10cSrcweir&apos; Finds a PartString, that is framed by the Strings &apos;Prestring&apos; and &apos;PostString&apos;
55cdf0e10cSrcweirFunction FindPartString(BigString, PreString, PostString as String, SearchPos as Integer) as String
56cdf0e10cSrcweirDim StartPos%, EndPos%
57cdf0e10cSrcweirDim BigLen%, PreLen%, PostLen%
58cdf0e10cSrcweir    StartPos = Instr(SearchPos,BigString,PreString)
59cdf0e10cSrcweir    If StartPos &lt;&gt; 0 Then
60cdf0e10cSrcweir        PreLen = Len(PreString)
61cdf0e10cSrcweir        EndPos = Instr(StartPos + PreLen,BigString,PostString)
62cdf0e10cSrcweir        If EndPos &lt;&gt; 0 Then
63cdf0e10cSrcweir            BigLen = Len(BigString)
64cdf0e10cSrcweir            PostLen = Len(PostString)
65cdf0e10cSrcweir            FindPartString = Mid(BigString,StartPos + PreLen, EndPos - (StartPos + PreLen))
66cdf0e10cSrcweir            SearchPos = EndPos + PostLen
67cdf0e10cSrcweir        Else
68cdf0e10cSrcweir            Msgbox(&quot;No final tag for &apos;&quot; &amp; PreString &amp; &quot;&apos; existing&quot;, 16, GetProductName())
69cdf0e10cSrcweir            FindPartString = &quot;&quot;
70cdf0e10cSrcweir        End If
71cdf0e10cSrcweir    Else
72cdf0e10cSrcweir        FindPartString = &quot;&quot;
73cdf0e10cSrcweir    End If
74cdf0e10cSrcweirEnd Function
75cdf0e10cSrcweir
76cdf0e10cSrcweir
77cdf0e10cSrcweir&apos; Note iCompare = 0 (Binary comparison)
78cdf0e10cSrcweir&apos;     iCompare = 1 (Text comparison)
79cdf0e10cSrcweirFunction PartStringInArray(BigArray(), SearchString as String, iCompare as Integer) as Integer
80cdf0e10cSrcweirDim MaxIndex as Integer
81cdf0e10cSrcweirDim i as Integer
82cdf0e10cSrcweir    MaxIndex = Ubound(BigArray())
83cdf0e10cSrcweir    For i = 0 To MaxIndex
84cdf0e10cSrcweir        If Instr(1, BigArray(i), SearchString, iCompare) &lt;&gt; 0 Then
85cdf0e10cSrcweir            PartStringInArray() = i
86cdf0e10cSrcweir            Exit Function
87cdf0e10cSrcweir        End If
88cdf0e10cSrcweir    Next i
89cdf0e10cSrcweir    PartStringInArray() = -1
90cdf0e10cSrcweirEnd Function
91cdf0e10cSrcweir
92cdf0e10cSrcweir
93cdf0e10cSrcweir&apos; Deletes the String &apos;SmallString&apos; out of the String &apos;BigString&apos;
94cdf0e10cSrcweir&apos; in case SmallString&apos;s Position in BigString is right at the end
95cdf0e10cSrcweirFunction RTrimStr(ByVal BigString, SmallString as String) as String
96cdf0e10cSrcweirDim SmallLen as Integer
97cdf0e10cSrcweirDim BigLen as Integer
98cdf0e10cSrcweir    SmallLen = Len(SmallString)
99cdf0e10cSrcweir    BigLen = Len(BigString)
100cdf0e10cSrcweir    If Instr(1,BigString, SmallString) &lt;&gt; 0 Then
101cdf0e10cSrcweir        If Mid(BigString,BigLen + 1 - SmallLen, SmallLen) = SmallString Then
102cdf0e10cSrcweir            RTrimStr = Mid(BigString,1,BigLen - SmallLen)
103cdf0e10cSrcweir        Else
104cdf0e10cSrcweir            RTrimStr = BigString
105cdf0e10cSrcweir        End If
106cdf0e10cSrcweir    Else
107cdf0e10cSrcweir        RTrimStr = BigString
108cdf0e10cSrcweir    End If
109cdf0e10cSrcweirEnd Function
110cdf0e10cSrcweir
111cdf0e10cSrcweir
112cdf0e10cSrcweir&apos; Deletes the Char &apos;CompChar&apos; out of the String &apos;BigString&apos;
113cdf0e10cSrcweir&apos; in case CompChar&apos;s Position in BigString is right at the beginning
114cdf0e10cSrcweirFunction LTRimChar(ByVal BigString as String,CompChar as String) as String
115cdf0e10cSrcweirDim BigLen as integer
116cdf0e10cSrcweir    BigLen = Len(BigString)
117cdf0e10cSrcweir    If BigLen &gt; 1 Then
118cdf0e10cSrcweir        If Left(BigString,1) = CompChar then
119cdf0e10cSrcweir            BigString = Mid(BigString,2,BigLen-1)
120cdf0e10cSrcweir        End If
121cdf0e10cSrcweir    ElseIf BigLen = 1 Then
122cdf0e10cSrcweir        BigString = &quot;&quot;
123cdf0e10cSrcweir    End If
124cdf0e10cSrcweir    LTrimChar = BigString
125cdf0e10cSrcweirEnd Function
126cdf0e10cSrcweir
127cdf0e10cSrcweir
128cdf0e10cSrcweir&apos; Retrieves an Array out of a String.
129cdf0e10cSrcweir&apos; The fields of the Array are separated by the parameter &apos;Separator&apos;, that is contained
130cdf0e10cSrcweir&apos; in the Array
131cdf0e10cSrcweir&apos; The Array MaxIndex delivers the highest Index of this Array
132cdf0e10cSrcweirFunction ArrayOutOfString(BigString, Separator as String, Optional MaxIndex as Integer)
133cdf0e10cSrcweirDim LocList() as String
134cdf0e10cSrcweir    LocList=Split(BigString,Separator)
135cdf0e10cSrcweir
136cdf0e10cSrcweir    If not isMissing(MaxIndex) then maxIndex=ubound(LocList())
137cdf0e10cSrcweir
138cdf0e10cSrcweir    ArrayOutOfString=LocList
139cdf0e10cSrcweirEnd Function
140cdf0e10cSrcweir
141cdf0e10cSrcweir
142cdf0e10cSrcweir&apos; Deletes all fieldvalues in one-dimensional Array
143cdf0e10cSrcweirSub ClearArray(BigArray)
144cdf0e10cSrcweirDim i as integer
145cdf0e10cSrcweir    For i = Lbound(BigArray()) to Ubound(BigArray())
146cdf0e10cSrcweir        BigArray(i) = &quot;&quot;
147cdf0e10cSrcweir    Next
148cdf0e10cSrcweirEnd Sub
149cdf0e10cSrcweir
150cdf0e10cSrcweir
151cdf0e10cSrcweir&apos; Deletes all fieldvalues in a multidimensional Array
152cdf0e10cSrcweirSub ClearMultiDimArray(BigArray,DimCount as integer)
153cdf0e10cSrcweirDim n%, m%
154cdf0e10cSrcweir    For n = Lbound(BigArray(),1) to Ubound(BigArray(),1)
155cdf0e10cSrcweir        For m = 0 to Dimcount - 1
156cdf0e10cSrcweir            BigArray(n,m) = &quot;&quot;
157cdf0e10cSrcweir        Next m
158cdf0e10cSrcweir    Next n
159cdf0e10cSrcweirEnd Sub
160cdf0e10cSrcweir
161cdf0e10cSrcweir
162cdf0e10cSrcweir&apos; Checks if a Field (LocField) is already defined in an Array
163cdf0e10cSrcweir&apos; Returns &apos;True&apos; or &apos;False&apos;
164cdf0e10cSrcweirFunction FieldinArray(LocArray(), MaxIndex as integer, LocField as String) As Boolean
165cdf0e10cSrcweirDim i as integer
166cdf0e10cSrcweir    For i = Lbound(LocArray()) to MaxIndex
167cdf0e10cSrcweir        If Ucase(LocArray(i)) = Ucase(LocField) Then
168cdf0e10cSrcweir            FieldInArray = True
169cdf0e10cSrcweir            Exit Function
170cdf0e10cSrcweir        End if
171cdf0e10cSrcweir    Next
172cdf0e10cSrcweir    FieldInArray = False
173cdf0e10cSrcweirEnd Function
174cdf0e10cSrcweir
175cdf0e10cSrcweir
176cdf0e10cSrcweir&apos; Checks if a Field (LocField) is already defined in an Array
177cdf0e10cSrcweir&apos; Returns &apos;True&apos; or &apos;False&apos;
178cdf0e10cSrcweirFunction FieldinList(LocField, BigList()) As Boolean
179cdf0e10cSrcweirDim i as integer
180cdf0e10cSrcweir    For i = Lbound(BigList()) to Ubound(BigList())
181cdf0e10cSrcweir        If LocField = BigList(i) Then
182cdf0e10cSrcweir            FieldInList = True
183cdf0e10cSrcweir            Exit Function
184cdf0e10cSrcweir        End if
185cdf0e10cSrcweir    Next
186cdf0e10cSrcweir    FieldInList = False
187cdf0e10cSrcweirEnd Function
188cdf0e10cSrcweir
189cdf0e10cSrcweir
190cdf0e10cSrcweir&apos; Retrieves the Index of the delivered String &apos;SearchString&apos; in
191cdf0e10cSrcweir&apos; the Array LocList()&apos;
192cdf0e10cSrcweirFunction IndexinArray(SearchString as String, LocList()) as Integer
193cdf0e10cSrcweirDim i as integer
194cdf0e10cSrcweir    For i = Lbound(LocList(),1) to Ubound(LocList(),1)
195cdf0e10cSrcweir        If Ucase(LocList(i,0)) = Ucase(SearchString) Then
196cdf0e10cSrcweir            IndexinArray = i
197cdf0e10cSrcweir            Exit Function
198cdf0e10cSrcweir        End if
199cdf0e10cSrcweir    Next
200cdf0e10cSrcweir    IndexinArray = -1
201cdf0e10cSrcweirEnd Function
202cdf0e10cSrcweir
203cdf0e10cSrcweir
204cdf0e10cSrcweirSub MultiArrayInListbox(oDialog as Object, ListboxName as String, ValList(), iDim as Integer)
205cdf0e10cSrcweirDim oListbox as Object
206cdf0e10cSrcweirDim i as integer
207cdf0e10cSrcweirDim a as Integer
208cdf0e10cSrcweir    a = 0
209cdf0e10cSrcweir    oListbox = oDialog.GetControl(ListboxName)
210cdf0e10cSrcweir    oListbox.RemoveItems(0, oListbox.GetItemCount)
211cdf0e10cSrcweir    For i = 0 to Ubound(ValList(), 1)
212cdf0e10cSrcweir        If ValList(i) &lt;&gt; &quot;&quot; Then
213cdf0e10cSrcweir            oListbox.AddItem(ValList(i, iDim-1), a)
214cdf0e10cSrcweir            a = a + 1
215cdf0e10cSrcweir        End If
216cdf0e10cSrcweir    Next
217cdf0e10cSrcweirEnd Sub
218cdf0e10cSrcweir
219cdf0e10cSrcweir
220cdf0e10cSrcweir&apos; Searches for a String in a two-dimensional Array by querying all Searchindexex of the second dimension
221cdf0e10cSrcweir&apos; and delivers the specific String of the ReturnIndex in the second dimension of the Searchlist()
222cdf0e10cSrcweirFunction StringInMultiArray(SearchList(), SearchString as String, SearchIndex as Integer, ReturnIndex as Integer, Optional MaxIndex as Integer) as String
223cdf0e10cSrcweirDim i as integer
224cdf0e10cSrcweirDim CurFieldString as String
225cdf0e10cSrcweir    If IsMissing(MaxIndex) Then
226cdf0e10cSrcweir        MaxIndex = Ubound(SearchList(),1)
227cdf0e10cSrcweir    End If
228cdf0e10cSrcweir    For i = Lbound(SearchList()) to MaxIndex
229cdf0e10cSrcweir        CurFieldString = SearchList(i,SearchIndex)
230cdf0e10cSrcweir        If  Ucase(CurFieldString) = Ucase(SearchString) Then
231cdf0e10cSrcweir            StringInMultiArray() = SearchList(i,ReturnIndex)
232cdf0e10cSrcweir            Exit Function
233cdf0e10cSrcweir        End if
234cdf0e10cSrcweir    Next
235cdf0e10cSrcweir    StringInMultiArray() = &quot;&quot;
236cdf0e10cSrcweirEnd Function
237cdf0e10cSrcweir
238cdf0e10cSrcweir
239cdf0e10cSrcweir&apos; Searches for a Value in multidimensial Array by querying all Searchindices of the passed dimension
240cdf0e10cSrcweir&apos; and delivers the Index where it is found.
241cdf0e10cSrcweirFunction GetIndexInMultiArray(SearchList(), SearchValue, SearchIndex as Integer) as Integer
242cdf0e10cSrcweirDim i as integer
243cdf0e10cSrcweirDim MaxIndex as Integer
244cdf0e10cSrcweirDim CurFieldValue
245cdf0e10cSrcweir    MaxIndex = Ubound(SearchList(),1)
246cdf0e10cSrcweir    For i = Lbound(SearchList()) to MaxIndex
247cdf0e10cSrcweir        CurFieldValue = SearchList(i,SearchIndex)
248cdf0e10cSrcweir        If CurFieldValue = SearchValue Then
249cdf0e10cSrcweir            GetIndexInMultiArray() = i
250cdf0e10cSrcweir            Exit Function
251cdf0e10cSrcweir        End if
252cdf0e10cSrcweir    Next
253cdf0e10cSrcweir    GetIndexInMultiArray() = -1
254cdf0e10cSrcweirEnd Function
255cdf0e10cSrcweir
256cdf0e10cSrcweir
257cdf0e10cSrcweir&apos; Searches for a Value in multidimensial Array by querying all Searchindices of the passed dimension
258cdf0e10cSrcweir&apos; and delivers the Index where the Searchvalue is found as a part string
259cdf0e10cSrcweirFunction GetIndexForPartStringinMultiArray(SearchList(), SearchValue, SearchIndex as Integer) as Integer
260cdf0e10cSrcweirDim i as integer
261cdf0e10cSrcweirDim MaxIndex as Integer
262cdf0e10cSrcweirDim CurFieldValue
263cdf0e10cSrcweir    MaxIndex = Ubound(SearchList(),1)
264cdf0e10cSrcweir    For i = Lbound(SearchList()) to MaxIndex
265cdf0e10cSrcweir        CurFieldValue = SearchList(i,SearchIndex)
266cdf0e10cSrcweir        If Instr(CurFieldValue, SearchValue) &gt; 0 Then
267cdf0e10cSrcweir            GetIndexForPartStringinMultiArray() = i
268cdf0e10cSrcweir            Exit Function
269cdf0e10cSrcweir        End if
270cdf0e10cSrcweir    Next
271cdf0e10cSrcweir    GetIndexForPartStringinMultiArray = -1
272cdf0e10cSrcweirEnd Function
273cdf0e10cSrcweir
274cdf0e10cSrcweir
275cdf0e10cSrcweirFunction ArrayfromMultiArray(MultiArray as String, iDim as Integer)
276cdf0e10cSrcweirDim MaxIndex as Integer
277cdf0e10cSrcweirDim i as Integer
278cdf0e10cSrcweir    MaxIndex = Ubound(MultiArray())
279cdf0e10cSrcweir    Dim ResultArray(MaxIndex) as String
280cdf0e10cSrcweir    For i = 0 To MaxIndex
281cdf0e10cSrcweir        ResultArray(i) = MultiArray(i,iDim)
282cdf0e10cSrcweir    Next i
283cdf0e10cSrcweir    ArrayfromMultiArray() = ResultArray()
284cdf0e10cSrcweirEnd Function
285cdf0e10cSrcweir
286cdf0e10cSrcweir
287cdf0e10cSrcweir&apos; Replaces the string &quot;OldReplace&quot; through the String &quot;NewReplace&quot; in the String
288cdf0e10cSrcweir&apos; &apos;BigString&apos;
289cdf0e10cSrcweirFunction ReplaceString(ByVal Bigstring, NewReplace, OldReplace as String)  as String
290cdf0e10cSrcweir    ReplaceString=join(split(BigString,OldReplace),NewReplace)
291cdf0e10cSrcweirEnd Function
292cdf0e10cSrcweir
293cdf0e10cSrcweir
294cdf0e10cSrcweir&apos; Retrieves the second value for a next to &apos;SearchString&apos; in
295cdf0e10cSrcweir&apos; a two-dimensional string-Array
296cdf0e10cSrcweirFunction FindSecondValue(SearchString as String, TwoDimList() as String ) as String
297cdf0e10cSrcweirDim i as Integer
298cdf0e10cSrcweir    For i = 0 To Ubound(TwoDimList,1)
299cdf0e10cSrcweir        If Ucase(SearchString) = Ucase(TwoDimList(i,0)) Then
300cdf0e10cSrcweir            FindSecondValue = TwoDimList(i,1)
301cdf0e10cSrcweir            Exit For
302cdf0e10cSrcweir        End If
303cdf0e10cSrcweir    Next
304cdf0e10cSrcweirEnd Function
305cdf0e10cSrcweir
306cdf0e10cSrcweir
307cdf0e10cSrcweir&apos; raises a base to a certain power
308cdf0e10cSrcweirFunction Power(Basis as Double, Exponent as Double) as Double
309cdf0e10cSrcweir    Power = Exp(Exponent*Log(Basis))
310cdf0e10cSrcweirEnd Function
311cdf0e10cSrcweir
312cdf0e10cSrcweir
313cdf0e10cSrcweir&apos; rounds a Real to a given Number of Decimals
314cdf0e10cSrcweirFunction Round(BaseValue as Double, Decimals as Integer) as Double
315cdf0e10cSrcweirDim Multiplicator as Long
316cdf0e10cSrcweirDim DblValue#, RoundValue#
317cdf0e10cSrcweir    Multiplicator = Power(10,Decimals)
318cdf0e10cSrcweir    RoundValue = Int(BaseValue * Multiplicator)
319cdf0e10cSrcweir    Round = RoundValue/Multiplicator
320cdf0e10cSrcweirEnd Function
321cdf0e10cSrcweir
322cdf0e10cSrcweir
323cdf0e10cSrcweir&apos;Retrieves the mere filename out of a whole path
324cdf0e10cSrcweirFunction FileNameoutofPath(ByVal Path as String, Optional Separator as String) as String
325cdf0e10cSrcweirDim i as Integer
326cdf0e10cSrcweirDim SepList() as String
327cdf0e10cSrcweir    If IsMissing(Separator) Then
328cdf0e10cSrcweir        Path = ConvertFromUrl(Path)
329cdf0e10cSrcweir        Separator = GetPathSeparator()
330cdf0e10cSrcweir    End If
331cdf0e10cSrcweir    SepList() = ArrayoutofString(Path, Separator,i)
332cdf0e10cSrcweir    FileNameoutofPath = SepList(i)
333cdf0e10cSrcweirEnd Function
334cdf0e10cSrcweir
335cdf0e10cSrcweir
336cdf0e10cSrcweirFunction GetFileNameExtension(ByVal FileName as String)
337cdf0e10cSrcweirDim MaxIndex as Integer
338cdf0e10cSrcweirDim SepList() as String
339cdf0e10cSrcweir    SepList() = ArrayoutofString(FileName,&quot;.&quot;, MaxIndex)
340cdf0e10cSrcweir    GetFileNameExtension = SepList(MaxIndex)
341cdf0e10cSrcweirEnd Function
342cdf0e10cSrcweir
343cdf0e10cSrcweir
344cdf0e10cSrcweirFunction GetFileNameWithoutExtension(ByVal FileName as String, Optional Separator as String)
345cdf0e10cSrcweirDim MaxIndex as Integer
346cdf0e10cSrcweirDim SepList() as String
347cdf0e10cSrcweir    If not IsMissing(Separator) Then
348cdf0e10cSrcweir        FileName = FileNameoutofPath(FileName, Separator)
349cdf0e10cSrcweir    End If
350cdf0e10cSrcweir    SepList() = ArrayoutofString(FileName,&quot;.&quot;, MaxIndex)
351cdf0e10cSrcweir    GetFileNameWithoutExtension = RTrimStr(FileName, &quot;.&quot; &amp; SepList(MaxIndex)
352cdf0e10cSrcweirEnd Function
353cdf0e10cSrcweir
354cdf0e10cSrcweir
355cdf0e10cSrcweirFunction DirectoryNameoutofPath(sPath as String, Separator as String) as String
356cdf0e10cSrcweirDim LocFileName as String
357cdf0e10cSrcweir    LocFileName = FileNameoutofPath(sPath, Separator)
358cdf0e10cSrcweir    DirectoryNameoutofPath = RTrimStr(sPath, Separator &amp; LocFileName)
359cdf0e10cSrcweirEnd Function
360cdf0e10cSrcweir
361cdf0e10cSrcweir
362cdf0e10cSrcweirFunction CountCharsinString(BigString, LocChar as String, ByVal StartPos as Integer) as Integer
363cdf0e10cSrcweirDim LocCount%, LocPos%
364cdf0e10cSrcweir    LocCount = 0
365cdf0e10cSrcweir    Do
366cdf0e10cSrcweir        LocPos = Instr(StartPos,BigString,LocChar)
367cdf0e10cSrcweir        If LocPos &lt;&gt; 0 Then
368cdf0e10cSrcweir            LocCount = LocCount + 1
369cdf0e10cSrcweir            StartPos = LocPos+1
370cdf0e10cSrcweir        End If
371cdf0e10cSrcweir    Loop until LocPos = 0
372cdf0e10cSrcweir    CountCharsInString = LocCount
373cdf0e10cSrcweirEnd Function
374cdf0e10cSrcweir
375cdf0e10cSrcweir
376cdf0e10cSrcweirFunction BubbleSortList(ByVal SortList(),optional sort2ndValue as Boolean)
377cdf0e10cSrcweir&apos;This function bubble sorts an array of maximum 2 dimensions.
378cdf0e10cSrcweir&apos;The default sorting order is the first dimension
379cdf0e10cSrcweir&apos;Only if sort2ndValue is True the second dimension is the relevant for the sorting order
380cdf0e10cSrcweir    Dim s as Integer
381cdf0e10cSrcweir    Dim t as Integer
382cdf0e10cSrcweir    Dim i as Integer
383cdf0e10cSrcweir    Dim k as Integer
384cdf0e10cSrcweir    Dim dimensions as Integer
385cdf0e10cSrcweir    Dim sortvalue as Integer
386cdf0e10cSrcweir    Dim DisplayDummy
387cdf0e10cSrcweir    dimensions = 2
388cdf0e10cSrcweir
389cdf0e10cSrcweirOn Local Error Goto No2ndDim
390cdf0e10cSrcweir    k = Ubound(SortList(),2)
391cdf0e10cSrcweir    No2ndDim:
392cdf0e10cSrcweir    If Err &lt;&gt; 0 Then dimensions = 1
393cdf0e10cSrcweir
394cdf0e10cSrcweir    i = Ubound(SortList(),1)
395cdf0e10cSrcweir    If ismissing(sort2ndValue) then
396cdf0e10cSrcweir        sortvalue = 0
397cdf0e10cSrcweir    else
398cdf0e10cSrcweir        sortvalue = 1
399cdf0e10cSrcweir    end if
400cdf0e10cSrcweir
401cdf0e10cSrcweir    For s = 1 to i - 1
402cdf0e10cSrcweir        For t = 0 to i-s
403cdf0e10cSrcweir            Select Case dimensions
404cdf0e10cSrcweir            Case 1
405cdf0e10cSrcweir                If SortList(t) &gt; SortList(t+1) Then
406cdf0e10cSrcweir                    DisplayDummy = SortList(t)
407cdf0e10cSrcweir                    SortList(t) = SortList(t+1)
408cdf0e10cSrcweir                    SortList(t+1) = DisplayDummy
409cdf0e10cSrcweir                End If
410cdf0e10cSrcweir            Case 2
411cdf0e10cSrcweir                If SortList(t,sortvalue) &gt; SortList(t+1,sortvalue) Then
412cdf0e10cSrcweir                    For k = 0 to UBound(SortList(),2)
413cdf0e10cSrcweir                            DisplayDummy = SortList(t,k)
414cdf0e10cSrcweir                            SortList(t,k) = SortList(t+1,k)
415cdf0e10cSrcweir                            SortList(t+1,k) = DisplayDummy
416cdf0e10cSrcweir                    Next k
417cdf0e10cSrcweir                End If
418cdf0e10cSrcweir            End Select
419cdf0e10cSrcweir        Next t
420cdf0e10cSrcweir    Next s
421cdf0e10cSrcweir    BubbleSortList = SortList()
422cdf0e10cSrcweirEnd Function
423cdf0e10cSrcweir
424cdf0e10cSrcweir
425cdf0e10cSrcweirFunction GetValueoutofList(SearchValue, BigList(), iDim as Integer, Optional ValueIndex)
426cdf0e10cSrcweirDim i as Integer
427cdf0e10cSrcweirDim MaxIndex as Integer
428cdf0e10cSrcweir    MaxIndex = Ubound(BigList(),1)
429cdf0e10cSrcweir    For i = 0 To MaxIndex
430cdf0e10cSrcweir        If BigList(i,0) = SearchValue Then
431cdf0e10cSrcweir            If Not IsMissing(ValueIndex) Then
432cdf0e10cSrcweir                ValueIndex = i
433cdf0e10cSrcweir            End If
434cdf0e10cSrcweir            GetValueOutOfList() = BigList(i,iDim)
435cdf0e10cSrcweir        End If
436cdf0e10cSrcweir    Next i
437cdf0e10cSrcweirEnd Function
438cdf0e10cSrcweir
439cdf0e10cSrcweir
440cdf0e10cSrcweirFunction AddListtoList(ByVal FirstArray(), ByVal SecondArray(), Optional StartIndex)
441cdf0e10cSrcweirDim n as Integer
442cdf0e10cSrcweirDim m as Integer
443cdf0e10cSrcweirDim MaxIndex as Integer
444cdf0e10cSrcweir    MaxIndex = Ubound(FirstArray()) + Ubound(SecondArray()) + 1
445cdf0e10cSrcweir    If MaxIndex &gt; -1 Then
446cdf0e10cSrcweir        Dim ResultArray(MaxIndex)
447cdf0e10cSrcweir        For m = 0 To Ubound(FirstArray())
448cdf0e10cSrcweir            ResultArray(m) = FirstArray(m)
449cdf0e10cSrcweir        Next m
450cdf0e10cSrcweir        For n = 0 To Ubound(SecondArray())
451cdf0e10cSrcweir            ResultArray(m) = SecondArray(n)
452cdf0e10cSrcweir            m = m + 1
453cdf0e10cSrcweir        Next n
454cdf0e10cSrcweir        AddListToList() = ResultArray()
455cdf0e10cSrcweir    Else
456cdf0e10cSrcweir        Dim NullArray()
457cdf0e10cSrcweir        AddListToList() = NullArray()
458cdf0e10cSrcweir    End If
459cdf0e10cSrcweirEnd Function
460cdf0e10cSrcweir
461cdf0e10cSrcweir
462cdf0e10cSrcweirFunction CheckDouble(DoubleString as String)
463cdf0e10cSrcweirOn Local Error Goto WRONGDATATYPE
464cdf0e10cSrcweir    CheckDouble() = CDbl(DoubleString)
465cdf0e10cSrcweirWRONGDATATYPE:
466cdf0e10cSrcweir    If Err &lt;&gt; 0 Then
467cdf0e10cSrcweir        CheckDouble() = 0
468cdf0e10cSrcweir        Resume NoErr:
469cdf0e10cSrcweir    End If
470cdf0e10cSrcweirNOERR:
471cdf0e10cSrcweirEnd Function
472cdf0e10cSrcweir</script:module>
473