Reg Exp
Web Design
Notes Client
Bytes and Booleans In Notes 6
Recently I wrote an agent that I knew was going to take a lot of memory while running. In an effort to save as much memory as possible, I decided to use the Byte data type for small numbers instead of the Integer data type. For those of you that don't know, a Byte is a small unsigned integer value. It only allows values in the range of 0 to 255. The Integer data type allows values in the range of -32,768 to 32,767. But the big difference is that the Integer data type takes up twice as much space as a Byte data type. The true difference is 1 byte to 2 bytes, but when you multiply that out by several arrays holding many thousands of values each, the difference can add up quickly.

So my agent was using the Byte data type. Some of the values I needed to store in documents. During my debugging, I noticed that the value wasn't being stored. I scratched my head for a while before realizing that Notes documents don't understand this data type. Even though it's a number, the value won't get stored in the field. You will always end up with an empty string. Here's some code you can try to show the difference:

Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Dim doc As NotesDocument
    Dim myByte As Byte
    Set db = session.CurrentDatabase
    Set doc = db.CreateDocument
    myByte = 50
    Call doc.ReplaceItemValue("MyByte", myByte)
    Call doc.Save(True, False, True)
End Sub

After running this code, you will have a document with one field called MyByte that has a value of "" (an empty string).

As it turns out, you need to covert that value into a data type that Notes understands - the most obvious choice is the Integer data type. So, the "ReplaceItemValue" statement becomes:

    Call doc.ReplaceItemValue("MyByte", Cint(myByte))

This time, when you run the agent you will have a document with on field that has a value of 50, which is what you want.

The same is true if you are using the Boolean data type and want to save the value (0 for False and -1 for True) in the document. You must convert the Boolean to an Integer when you are storing it in a document.

As an aside, a Boolean variable takes up 2 bytes, just like an Integer does. So the only benefit to using that data type is for readability and support - you know that the value is going to be a true/false value. You could choose to use a Variant for your true/false values, but each one of those takes up 16 bytes of storage - way more than is necessary.