Fields and variants

I want to read the content of a field into a variable. Update a few items of that variable and write the content back to the original field.

How to solve, thanks

My code:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Set db = session.currentdatabase

Set view = db.GetView(“Myview”)

Set doc = view.GetFirstDocument

test = doc.myfield ’ myfield is numeric

’ replace a few values

test(2)= 25

test(6) = 30

Do Until doc Is Nothing

’ replace field

’ here comes the problem:

’ Message: Notesitem cannot be set to an array of mixed data types

doc.myfield=test

doc.Save False, True

Set doc = view.GetnextDocument(doc)

Loop

Subject: Fields and variants

Notes does not recognise integers as field values. All numbers are floating point doubles. When you store test(2)=25 you are storing a variant integer value in an array of variant doubles. LS allows this but you can’t store it in a notes item.

Subject: I have to disagree …

There is no problem assigning (array of) integers to a notes item.But you cannot assign an array of variants, even when it contains only variant doubles.

I was wrong : see the rest of this thread

Subject: RE: I have to disagree …

Just done itDim ar(1) As Variant

ar(0)=1.2

ar(1)=2.3

Call doc.replaceitemvalue("nn",ar)

no problem

and of course you can assign an array of integers (they will be converted to doubles when stored)

but not an array of variants containing doubles and integers

Subject: You’re absolutely right …

I didn’t read your posting well, and I’ve been telling lies …

Mea culpa!

Subject: ignore this …

Subject: Fields and variants

Insert some debugging code to see what the data types in the array are :

for t=0 to ubound(test)

print TypeName(test(t))

next

then you’ll see what the original data type is of the array.

Some things to consider:

  • non existing fields in a document allways return a string array with one element : an empty string.

  • Field of the type checkbox, radio butons, lists and comboboxes allways return strings …

De groeten,

Joris

Subject: Just change it slightly…

test(2)= Cdbl(25)test(6) = Cdbl(30)