Subscript out of range

Further to my other post ‘I just can’t figure it out…’(I’m trying to set a field so that the newest value appears at the top - maybe it will work if I turn my monitor upside down?)

Now, I tried to get the value from the field, set it to blank, then loop through the existing values and put them in in the right order…

However, now I am getting subscript out of range, when it gets to number one.

Here’s the code:

Sub Initialize

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument

'Call uidoc.Save

Dim Doc As NotesDocument

Set Doc = uidoc.Document

Dim tMainProjectPhase As Variant

tMainProjectPhase = doc.MainprojectPhase

Dim strMainProjectPhase As String

strMainProjectPhase = Cstr(tMainProjectPhase(0))

Dim user As String

user = session.CommonUserName



Dim GetValue As Variant

GetValue = doc.StatusLog

Call uidoc.FieldSetText("StatusLog","") 



Elements1= Evaluate(|@Elements(StatusLog)|,doc)





'Call uidoc.Reload

Call uidoc.FieldAppendText _

( "StatusLog", "," )

Call uidoc.FieldAppendText _

( "StatusLog", "The project status was changed from " +  Cstr(currentStatus)  + " to " + NewStatus + " by " + user  + " on " +Cstr(Date) + " at " + Cstr(Time) + ".") 

Call uidoc.FieldAppendText _

( "StatusLog", "," )

Cstr1 = Cstr(Elements1(0))

'Cval1 = Cval(CStr1)	

For x = 0 To Cstr1

	Call uidoc.FieldAppendText _

	( "StatusLog", GetValue(x))

Next



Call uidoc.Save

Call Doc.Save(True,True)

End Sub

Any ideas? Here’s the line it bugs out on:

For x = 0 To Cstr1

	Call uidoc.FieldAppendText _

	( "StatusLog", GetValue(x))

Subject: Subscript out of range

what about this… just off the top of my head:

dim i as integer

dim xfield(0) as string

dim item as notesitem

…

xfield(0)=newestvalue

i=1

set item = doc.getfirstitem(existingfield)

forall xvalues in item.values

redim preserve xfield(0 to i)

xfield(i)=xvalues

i=i=1

end forall

doc.existingfield=xfield

Subject: Subscript out of range

This is a little more “expensive” (in processor time), but it works for us. The code just keeps a numeric list in descending order that is incremented each time a document is saved.doc.RevisionNumber = Evaluate( |@Text(1+@TextToNumber(@Subset(RevisionNumber;1))) : @Subset(RevisionNumber; 9)|, doc)

It just keeps the last 10 revisions.

Also, it might be more work than it’s worth, but you could look at ArrayAppend.

Regards,

Don

Subject: for my own edification…

my solution is slow? i do stuff like that all the time and am always looking to improve the speed of my code.

Subject: Your bug line

Your bug line is because of this code line:

Call uidoc.FieldSetText(“StatusLog”,“”)

Elements1= Evaluate(|@Elements(StatusLog)|,doc)

When you make ‘StatusLog’ field null, have you thought what could be the value of Elements1 and then you are using this value, in forloop.

In forloop, I guess you are using string which you need to convert to integer:

For x = 0 To Cstr1

should be

For x = 0 To cint(Cstr1)