views:

20

answers:

2

I have a lotus view that stores a number. I need to perform some math against the value, but I am having a lot of problems getting the types to match up.

doc.numOfGold = numGold 

and CInt(doc.numOfGold) = numGold

and CInt(doc.numOfGold) = CInt(numGold)

and doc.numOfGold = CInt(numGold)

all return type mismatch. I've tried changing the column properties to treat it as a decimal, with no better luck.

Any thoughts?

Thanks!

+1  A: 

Never access a field like this: "doc.fieldname". User doc.GetItemValue("fieldname")(0), this returns the correct type.

If doc.numOfGold is a numberfield, and numGold is an int, it should work like this:

Dim numOfGold as integer
numOfGold = doc.GetItemValue("numOfGold")(0)

if doc.numOfGold is a textfield, you have to do a conversion, e.g. val(doc.GetItemValue("numOfGold")(0))

Also verify that your field value is not an empty string, e.g. use a field validation formula.

cwaidner
+5 if I could. Thanks. I didn't know about the val statement.
Kris.Mitchell
Thanks, as long as it helps ;-)
cwaidner
A: 

Never access a field like this: "doc.fieldname".

Bit harsh, accessing a document field value is perfectably acceptable:

x = doc.FieldName(0)

Doc.FieldName = ScalarValue

or even

Doc.FieldName = ArrayOfValues

To be sure of success, you may want to see if 'Doc.HasItem("FieldName")' first (true for getFirstItem too).

NB: GetFirstItem is the direct way to get the field value, for max performance:

x = doc.getFirstItem("FieldName").Values(0)

As this avoids 'default properties'.

Also, the 'assumed default' 'doc.FieldName(0)' can be 'overlooked' by error reporting/syntax checking

andora