Script error "Variant doesn't contain a container"

I made a db which is functioning good and this is a part of the script:
(field trev is a radio button)

Case 2       :
      If doc.trev(0)="Y" Then
                subj = "Please approve this document!"
      tit = "Dear FA Team!"
      txt = "Please click on the document link to open the request!"
            MailDoc.SendTo = faname
            doc.Level = 3
            doc.Level_Title = "FA Team"
      Else
            subj = "Sorry, but your request was refused!"
            tit = "Dear Requestor!"
            txt = "Please click on the document link to open the request!"
            MailDoc.SendTo = doc.reqn                              
            doc.Level = 7
            doc.Level_Title = "Refused"
            End If

Now I've to update this program.
I've to add this: If the field "sum1" or "sum2" more than 1000 and field "trev" = yes then
doc.Level = 3
doc.Level_Title = "FA Team"

But when..
If the field "sum1" or "sum2" less than 1000 and field "trev" = yes then
doc.Level = 4
doc.Level_Title = "SDep Team"

The else part should stay
doc.Level = 7
doc.Level_Title = "Refused"

I tried this below but I get the error message "Variant doesn't contain a container"

If doc.trev(0)="Y" And doc.sum1(0)<"1000" Or doc.trev(0)="Y" & doc.sum2(0)<"1000" Then
subj = .......
tit = .........
txt = ..........
Can you help me with this?


verto33Asked:
Who is Participating?
 
qwaleteeConnect With a Mentor Commented:
FYI, "Variant doesn't contain a container" means this.  A variant is a variable or expression in LotusScript whose type is not predetrmined, so it canhold anything.  Thatmeans it can hold scalars (strings, numers, booleans), arrays, lists, Lotus objects, or COM objects.

When you reference a variant as an array -- variantExpression(subscript) -- the syntax is OK, but the variant must actually contain an array.  If the variant contains something else, you will get the error, Variant doesn't contain a container -- a CONTAINER being a connection to a complex type such as an array.

doc.trev is a shorthand way of saying doc.getItemValue("trev"), and getItemValue returns a variant, which happens to always be an array, because of the design of the fnction.  But, if it does not return an array, then you have a variant returning a non-array that you are referncing as if it is an array, and BOOM, you get the error.

Similar hings happen if the variant is referenced as if it contains a Lotus or COM object, if in fact the variable does not contain such as object.  I believe you get Variant does not contain an object in that case.  You would also get the identical error if you were refencing it as a list, if t contained neither array nor list.

Writing al this, I realize there is a hole in the logic of my previous comment.  Even if the field does not exist, doc.trev (or doc.sum1/sum2) will still return a single element array, with the single element being an empty string.  So, you should not get Variant doesn't contain a container.  That DOES happen if yuo use, say. doc.noteID, which returns not a field called noteID, but a property, NOTEID, of the NotesDocument object... and that property is a scalar (string), so you would get Variant doesn't contain a container.  This seems to be smething else, since none of TREV, SUM1, and SUM2 are properties, so they should always be trated as NotesItem shorthand references.
0
 
Sjef BosmanGroupware ConsultantCommented:
There are several problems, I think:
1) Where the error comes from, I can't see that's from the code you gave
2) You seem to have problems with operator precedence; use parentheses to get it right (and is like multiplication, or is addition).
        A and B or A and C
    is equivalent to
        A and (B or C)
3) The fields sum1 and sum2, are they numeric? Then remove the double-quotes, as in
        If doc.trev(0)="Y" And (doc.sum1(0)<1000 Or doc.sum2(0)<1000) Then
4) Your logic probably isn't quite right. You want to do one thing if a>1000 or b>1000,
    you want to do another thing if a<1000 or b<1000 but did you realise that you
    will always use the first alternative when a=500 and b=1500?
    The Else-part will therefore ONLY be used when a=1000 AND b=1000!
0
 
verto33Author Commented:
The fields sum1 and sum2, are numeric.
But only one of them is visible at the same time.
I mean there is a radio button and if the user select "Yes" he can see only the sum1 field and if he select "No" he only can see the sum2 field.

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Sjef BosmanGroupware ConsultantCommented:
Ah, I get it. So it's more like
    Dim trev As String
    Dim sumx As Double ' or Integer

    trev= doc.trev(0)
    If trev="Y" Then
        sumx= doc.sum1(0)
    Else
        sumx= doc.sum2(0)
    End If
    If sumx<1000 Then
        ...
    Else
        ...
    End If

Is that more like it?
0
 
verto33Author Commented:
Yes, but I use Formula not script for that, like below:
The value of sum1 is:

x:= price/kursh* piece/1000;
y:= price/kursg* piece/1000;
z:= price/kursj* piece/1000;

@If(currency="HUF"; x; @If(currency="GBP";y; @If(currency="JPY";z;"")));

numeric fields are price,kursh,piece
dialog list is currency (HUF,GBP,JPY etc)
0
 
verto33Author Commented:
I use Hide when ..
If trev="Y" the sum2 field is hidden
0
 
mssturgeonCommented:
At the beginning of you script, add this bit:

On Error Goto ErrorHandler

and at the end (before 'End Sub') add this bit:

Exit Sub
   msgbox("Error "& Err &" [line "& Erl &"] "& Error$)
   End



This will tell you what line is giving the error and you should be able to troubleshoot it better
0
 
mssturgeonCommented:
Just noticed this as well ... you code:

If doc.trev(0)="Y" And doc.sum1(0)<"1000" Or doc.trev(0)="Y" & doc.sum2(0)<"1000" Then



The '&' is used for string concatenation in this context,  I imagine you wanted to use 'And'?
0
 
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:


Yes, okay, but you need it in Script as well. If trev="Y" then the field sum2 will have no value (null), so you shouldn't even evaluate it.

The @If statement needs some polishing up as well. The complete syntax of the @If is
    @If( cond1; stat1; cond2; stat2; cond3; stat3; ....; cond_n; stat_n; statz)

So
    @If(currency="HUF"; x; @If(currency="GBP";y; @If(currency="JPY";z;"")));
could be written as
    @If(currency="HUF"; x; currency="GBP"; y; currency="JPY"; z; "");

Do use an @IsError() to test whether the computations you do are valid.

If I still didn't understand what you want, please give a full descruption of your goals. By the way, did you try to use the debugger?
0
 
Sjef BosmanGroupware ConsultantCommented:
Heh, the "&"... missed it.

Eagle eyes, Shane? :)
0
 
Sjef BosmanGroupware ConsultantCommented:
Tiny correction:

>and at the end (before 'End Sub') add this bit:

>   Exit Sub
ErrorHandler:  ' added
>   msgbox("Error "& Err &" [line "& Erl &"] "& Error$)
>   End
0
 
mssturgeonCommented:
Doh!
0
 
verto33Author Commented:
I used the debugger and it definitely shows the error message in the line:

If doc.trev(0)="Y" And doc.sum1(0)<"1000" Or doc.trev(0)="Y" & doc.sum2(0)<"1000" Then

0
 
Sjef BosmanGroupware ConsultantCommented:
Then go through points 1-5...
0
 
mssturgeonCommented:
... and change that ampersand!
0
 
verto33Author Commented:
I deleted the & sign and reduced the script but still to

If doc.trev(0)="Y" And doc.sum1(0)<1000  Then

but still the same error. What can be wrong with this tiny code?
If I delete this -->And doc.sum1(0)<1000 then no error message.


0
 
mssturgeonCommented:
Are you sure there is an item called "sum1" on the form?
0
 
Sjef BosmanGroupware ConsultantCommented:
mssturgeon,

> ... and change that ampersand!
That was point 5 :-))

verto33,

It seems you are coding first and then designing. The other way round is much easier... I have the idea there's something wrong with the logic of your code.
Can you give us your current (full) code? And did you try something like the alternative I gave, in my 2nd response?

Sjef
0
 
qwaleteeCommented:
That ALMOST CERTAINLY indicates a field that does not exist. Pleas replace the IF with teh followng code

Dim trev, sum1, sum2
If doc.hasItem("trev") Then trev = doc.trev(0) : Else trev = "N" : Print "No trev field!" : Beep
If doc.hasItem("sum1") Then sum1 = doc.sum1(0) : Else sum1 = "0" : Print "No sum1 field!" : Beep
If doc.hasItem("sum2") Then sum2 = doc.sum2(0) : Else sum2 = "0" : Print "No sum2 field!" : Beep
If (trev="Y" And sum1<1000) Or (trev="Y" And sum2<1000 Then

Check for beeps and messages in the status bar.  Once we resolve that, we'll have to go through your logic, because, as Sjef says, the planning leaves something to be desired, both internms of system design in your form and in terms of the code here.  Probably be a good idea to explain the business logic.
0
 
Sjef BosmanGroupware ConsultantCommented:
Confused?? You won't be after the next episode of...

?
0
 
verto33Author Commented:
I will print it and will read at home because during the work I have little time.
But I will answer.

I changed some fields and it is working but I have no idea what the reason was.
I have subforms in the database but only one is in use at the same time.
There is a sum1 field on the one subform (editable) and there is a sum1 field on the other subform (computed) gets the value from the sum1 editable field.

Should I use the value from the editable or from the computed sum1 field?
And is it a problem if there is the field with the same name? (1 is in use at the same time)
0
 
mssturgeonConnect With a Mentor Commented:
you will simply have multiple Items on the document, then ... in which case you might have to determine which is the "good" one.  And you can still access a computed field, as long as it is not "Computed for Display" ... in which case you cannot access it from the back-end (I don't believe).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.