?
Solved

Script error "Variant doesn't contain a container"

Posted on 2005-05-13
22
Medium Priority
?
679 Views
Last Modified: 2013-12-18
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?


0
Comment
Question by:verto33
  • 8
  • 6
  • 6
  • +1
22 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13994409
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
 

Author Comment

by:verto33
ID: 13994625
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13994691
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:verto33
ID: 13994953
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
 

Author Comment

by:verto33
ID: 13995021
I use Hide when ..
If trev="Y" the sum2 field is hidden
0
 
LVL 3

Expert Comment

by:mssturgeon
ID: 13995168
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
 
LVL 3

Expert Comment

by:mssturgeon
ID: 13995181
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
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 60 total points
ID: 13995215


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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13995230
Heh, the "&"... missed it.

Eagle eyes, Shane? :)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13995276
Tiny correction:

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

>   Exit Sub
ErrorHandler:  ' added
>   msgbox("Error "& Err &" [line "& Erl &"] "& Error$)
>   End
0
 
LVL 3

Expert Comment

by:mssturgeon
ID: 13995325
Doh!
0
 

Author Comment

by:verto33
ID: 13995394
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13995457
Then go through points 1-5...
0
 
LVL 3

Expert Comment

by:mssturgeon
ID: 13995471
... and change that ampersand!
0
 

Author Comment

by:verto33
ID: 13995519
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
 
LVL 3

Expert Comment

by:mssturgeon
ID: 13995572
Are you sure there is an item called "sum1" on the form?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13996093
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 13996924
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
 
LVL 31

Accepted Solution

by:
qwaletee earned 75 total points
ID: 13997029
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 13998510
Confused?? You won't be after the next episode of...

?
0
 

Author Comment

by:verto33
ID: 14018621
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
 
LVL 3

Assisted Solution

by:mssturgeon
mssturgeon earned 60 total points
ID: 14018685
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question