Getting variant does not contain a container depending on information on similar code

I have a an issue with the error variant does not contain a container. I have two agents one is were I have the tech put in the number of hours he/she work on preparing the laptop for a requestor. The agent then using several sub routines will notify the stockroom machine is prepped and sends emails to tech manager and message to the tech as to the original time he claimed. The agent - the hours field in the form is a number field and editable. The agent declares the hours as Dim hours as Variant then in the code sets value by using the hours = doc.getitemvalue(“hours”) then in message the value is place in the body with hours(0)

Agent then requests do you want to notify user if not then only the tech assigned for delivery will be notified. If you select yes this agent calls another agent ‘send message’ which is coded below. Here the duration is a number field computed by formula on number of business days based on the start and end date fields. When I use set duration = doc.getitemvalue(‘duration”) I get error message of ‘type mismatch’ to make it happy I changed it to set duration =doc.getfirstitem(“duration”) but, when it gets to the message variable duration(0) I get ‘Variant does not contain a container’ what is wrong here and is it because one is a computed number field and the other not computed. If that is the case, what is work around or error in code. I rem out original line and copy it twice and split the message to see which was the offender I found not only duration but tech(0) also has issue. Yet requestor, and assignee are fine and these are all name fields. Code is below.

Option Public

Option Declare

Dim doc As NotesDocument

Dim requestor As Variant

Dim mfgr As Variant

Dim Model As Variant

Dim StartDate As NotesDateTime

Dim EndDate As NotesDateTime

Dim duration As Variant

Dim tech As Variant

Dim Assignee As Variant

Dim sdItem As NotesItem

Dim editem As NotesItem

Sub Initialize

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim memo As NotesDocument

Dim doc As NotesDocument

Dim body As NotesRichTextItem

Set db = session.CurrentDatabase

Set doc = ws.CurrentDocument.Document

Set sditem = doc.GetFirstItem("StartDate")

Set editem  = doc.GetFirstItem("EndDate")

Set StartDate =sditem.DateTimeValue

Set EndDate = editem.DateTimeValue

Set duration =doc.GetItemValue("Duration")

mfgr = doc.GetItemValue("mfgr")

Model= doc.GetItemValue("Model")

Requestor = doc.GetItemValue("Requestor")

Set tech = doc.GetFirstItem("tech")

Assignee = doc.GetItemValue("Assignee")

Set memo = db.CreateDocument

memo.Form = "Memo"

memo.Subject = "Laptop Request for a  " & mfgr(0) & " " &Model(0) & " for " & Requestor(0)

Set body = memo.CreateRichTextItem ( "Body" )

'create the body of the mail message for the requester

Call body.AppendText(" A Laptop has been checked out for a "& mfgr(0) & "  " & Model(0) )

Call body.AppendText(" loan to start on " & StartDate.DateOnly & " and to be returned on " & EndDate.DateOnly)

Call body.AppendText( " or the following day after "  & EndDate.DateOnly  &  ".")

Call body.AppendText ( " loan is for  " & duration(0) & "  Days and has been checked out  by " & tech(0) & "." )

Call body.AddNewline ( 2 )

Call body.AppendText ( "To be delivered by: " & Assignee(0))

Call body.AddNewline ( 2 )

Call body.AppendText ( "If you no longer need this request. Please notify technician and the it service desk of cancellation. " )

Call body.AddNewLine (2)

Call body.AppendText("Thank You")

Call body.AddNewline(2)

Call body.AppendText ( "Local Support " )

Call memo.Send ( False, Requestor(0))

End Sub

Subject: getting variant does not contain a container depending on information on similar code.

The statement:

Set duration = doc.getitemvalue(‘duration”)

is not wrong because you called the wrong method. It’s wrong because the Set statement is only used to assign object values, it fails if the value being assigned is not an object. The return value of GetItemValue is not an object, it’s an array. Take out the word Set and you’ll be fine.

GetFirstItem does return an object, so Set works there. But an object is not a container – only arrays and Lists are containers. The message is telling you that you can’t use the array reference (0) following an variable that doesn’t contain an array.