Array Initialize
Assign a great number of elements to an array
You can view feedback to this tip!
In LotusScript, it's not possible to initialize a one dimension table in onestep with more than one element. Thanks to this script, you can assign a great
number of elements to an array and this is in two line code!
----------------------------------------------
Example :
Dim Chaine As String
Dim Array() As String ' --> Tableau de 7 ?l?ments
Chaine = "Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi,Dimanche" ' --> 7 element
Call Arrayass(Array,String)
-------------------------------------------
After execution, the Array variable contents is:
[[Lundi][Mardi][Mercredi][Jeudi][Vendredi][Samedi][Dimanche]]
Array(1)=Lundi
Array(5)=Vendredi
Array(7)=Dimanche
Note : The separator must be a "," or a ";"
Sub Arrayass(Tabl() As String, Chaine As String)
Dim i,start,Element As Integer
Dim temp As String
start=1
Element=1
Do
i=1
Do
temp=Mid$(Chaine,start,i)
i=i+1
Loop Until Right(temp,1)="," Or Right(temp,1)=";" Or start+i-2=Len(Chaine)
Tabl(Element)=LTrim$(Left(temp,Len(temp)-1 + (start+i-2=Len(Chaine))*(-1)))
start=start+i-1
Element=Element+1
Loop Until Len(Chaine)=start-1
End Sub
This is beautiful work by Fabient, but there are a couple of "gotchas" in making it work.
The following will correctly set up and call the code:
Dim Chaine As String Dim Array(7) As String 'Vary the 7 according to 'the elements you plan to put 'into the array. 'The posted code doesn't 'declare the array length 'producing an out of bounds error 'after the first element Chaine = "Lundi,Mardi,Mercredi,Jeudi,Vendredi,Samedi,Dimanche" ' --> 7 elements Call Arrayass(Array,Chaine) 'show the results on the status bar For myi = 1 To 7 Print Array(myi) Next