More Notes Annoyances
Here's another LotusScript headache from my past week of coding. It's not like I was doing any power-coding or anything. So why do I seem to have so many issues? Am I just a bad coder maybe? Imagine the simple code below:
Dim doc1, doc2 As NotesDocument Call doc2.MakeResponse(doc1)
Obviously there are some lines missing to set the variables. Still, nothing special. So, why did I get the following error when it ran:
68: Type Mismatch on DOC1
Because I needed to declare the document variables on separate lines, like so:
Dim doc1 As NotesDocument Dim doc2 As NotesDocument Call doc2.MakeResponse(doc1)
Needless to say it took me ages to work that one out. It's one thing being able to spot logic errors in code. It's another being able to guess the illogical errors in LotusScript
Here's another error Notes threw my way recently when trying to open a certain design element:
No prizes for guessing what kind of element I was trying to open. Words can't describe how annoying this was. I had to delete it and start again!
Anyway, I promised myself I'd stop being so down about Notes. Sometimes I just can't help. This blog is my couch and you're my shrink. I feel better now. Same time next week?
The type declaration annoyance is not specific to LotusScript. You would have the same problem if you'd be using the VBA language.
{Link}
You can still use one line with:
Dim doc1 As NotesDocument, doc2 As NotesDocument
Cannot say it ever annoyed me though. I like to type my variables.
err....i tried the same code but am not getting an error. i didnot call the save method after the makeresponse line as i was doing quick and dirty testing.
i know i have done similar stuff before without problems. i normally go with
Dim doc1 As NotesDocument, doc2 As notesDocument
but Dim doc1, doc2 as notesdocument should work....
i get a type mismatch when i do
Dim doc1, doc2
Call doc1.MakeResponse(doc2)
which i can understand, as makeresponse is expecting a document object and doc2 is a vaariant countainer, though it holds a document.
Dim doc2, doc2 As NotesDocument ???
Call doc1.MakeResponse(doc2)
I gues you meant :
Dim doc1, doc2 As NotesDocument
...
Call doc1.MakeResponse(doc2)
and this (at list in R7 Beta 3) will work.
Dim s As New notessession
Dim db As NotesDatabase
Dim doc1, doc2 As NotesDocument
Set db=s.CurrentDatabase
Set doc2=New NotesDocument(db)
doc2.form="DeleteMe"
doc2.Save False,False
Set doc1=New NotesDocument(db)
Call doc1.MakeResponse(doc2)
Msgbox doc1.getitemvalue("$REF")(0)
I've run into this in the past. When you declare
dim doc1, doc2 as NotesDocument
for some reason Notes only picks up the doc2 as NotesDocument. It automatically assigns doc1 as a variable and not a document. It works this way on all assignments, views...documents...rtf's whatever.
Corey,
Read Alexandre's comment above. This isn't specific to Notes (or more accurately LotusScript).
More a case of RTFLM.
P.S. LM = Language Manual
I thought that you could declare variables this way? e.g:
Dim s1, s2, s3 as String
Would that not result in three string variables? Do they all have to be "typed" explicitly or not?
If it's documented that it doesn't work then why does it work for Yuval and Veer?
No -- only variables followed immediately by "As Type" will be anything other than a Variant. That's the same behaviour one gets in Visual Basic up to VB6.
veer's syntax was:
Dim doc1 As NotesDocument, doc2 As NotesDocument
Note that while both appear in the same Dim statement, they both have their own "As Type" clause. Yuval was working in ND7, and the behaviour may have changed, but I doubt it -- a lot of code would break if things that had previously been Variants were recompiled as typed values. One of the big selling features of VB.NET was that your declaration statement would finally result in two NotesDocuments, but Microsoft's upgrade translator would have translated your declaration statement to:
Dim doc1 As Object
Dim doc2 As NotesDocument
("Object" is the new .NET Variant.)
it end up with one variant and one document and you can use the variant as document unless you try to put him in a function that get document type only, this is why it will work for:
call doc1.makeresponse(doc2)
and not for
doc2.makeresponse(doc1)
becuase the way you declared it is
doc1, (variant) doc2 as notesdocument.
As far as i know - same in VB too.
Jake,
You might want to verify one thing. In your code you would not get the error if your call was:
1)
Dim doc1, doc2 As NotesDocument
Call doc1.MakeResponse(doc2)
However, you will get an error if you did:
2)
Dim doc2, doc1 As NotesDocument
Call doc1.MakeResponse(doc2)
Since the code you pasted in your blog has both as doc2s...( which lotuscript compiler won't let you compile, hence i guess is a typo when you were putting in this blog ), you need to check if you did 1 or 2 ).
Hope this helps.
Woops. Fixed a typo in the main post.
Ok, I've learnt something today. Another painful lesson. I'm too saw from yesterday's flogging to repeat that. Today's was painful by virtue of public humiliation.
Talking of RTFM. Show me the line in TFM (Notes Designer Help that is) that tells me about this!
Jake:
I remember seeing that Notes will ONLY type the var that precedes the type definition and everything else is typed as a string. That's why
dim str1, str2, str3 as String works with no problem.
It's on the document entitled "Declaring scalar variables explicitly" in the LotusScript Language section, and may live elsewhere.
@John: Nope -- everything that's missing an "As Type" clause (or a suffix, if you're into perversions) will be a Variant. Your statement works because Variants can contain strings.
Jake -
About your "Not a Form" error ....
There is a bug in 6 whereby a form can become corrupt and lose the fields that tell it it's a form. Had this happen a few months back and lost a few days worth of work. Now, if I have a complex form I try to put as much as possible on subform(s).
-- Mike
@Blop. Thanks for the feedback. I'm coming at this from a "Notes" developer standpoint. I didn't do any coding prior to Notes.
Jake
About the "Not a Form" error. I had this problem recently as well. I found some info on the IBM website after googling it. My problem turned out to be that I was trying to embed the same subform on two other subforms.
I had some navigation set up on a subform. I wanted to display it on the left side one way (with css) and at the bottom of the page/form another way. Didn't want to have to make changes twice in the future so I thought I could enter the nav on one subform, and then embed that subform in two seperate subforms.
Anyway, when I included the subform for the left navigation, and then the subform for the bottom navigation, it choked and I got the error message that you referenced.
It was because the main form now contained the navigation subform in two separate places.
It allowed me to save the form once, but when I tried to open the form again, I got the error. Had to delete the form and start again.
I just encountered the "Not a Form" error earlier this week. Apparently I shouldn't have cut a subform from within a form and placed it into another subform on the same form. There's not a good reason for doing what I was doing but I did it without error. It wasn't until after I saved and closed the other forms, using the modified subform, that I received the error.
I've recently been working with VisualStudio.Net and don't encounter near as many headaches when developing. There are also tons of features, style sheet editor to name one, in VS.Net that the Lotus Domino Designer doesn't give us.
Thanks Stan. You really are a big know-it-all aren't you ;o)
I'm just going to quit while I'm ahead now. That's enough embarrassment for one day.
Jake, I know it's there because I went through a similar (but not quite so public, thank the Big Guy) "learning experience" myself a while back. Oooh, much fun was had at the expense of Stan that day....
Syntax
{ Dim | Static | Public | Private } variableDeclaration [ , variableDeclaration ]...
type
Optional for scalar variables, lists, and arrays. A valid LotusScript data type, user-defined data type, user-defined class, or product class. This specifies the type of variableName.
Specifying the data type
Either dtSuffix or As type can be specified in variableDeclaration, but not both. If neither is specified, the data type of variableName is Variant.
(It applies to variableName not variableNames)
Zist iz vahts in ze help file! See you next week. :)
Thanks for sharing your frustration.
Made us all have a good laugh.
I usually follow such days, with a lot of swearing and yelling, "Stupid Notes!".
Keep up the good work.
We all know Notes is frustrating. That caused me to take up Oracle a few years ago.
All I can say is, if you think Notes is frustrating... you ain't seen nothin'
I think it's time we all realised that despite it's frustrations and limitations, Notes is still wonderful stuff. Ray Ozzie and Co hit upon some wonderful ideas whose time had come: replication, security, a flexible application platform coupled with excellent comms.
More than that, it's time WE started to lead the revival, to stop apologising because Notes is not new and trendy. Let's get out there ahead of IBM and talk it up. I'm game.
Regarding it not being new and trendy - the windscreen wiper isn't either - it's been around for over 80 years now and has still not been bettered.
Having said that... I know what you mean... in my case I swear at tables every time I attempt to use them - been doing so for 15 years now.
Corey:
<snip>
It was because the main form now contained the navigation subform in two separate places.
It allowed me to save the form once, but when I tried to open the form again, I got the error. Had to delete the form and start again.
</snip>
Actually, you don't have to start all over; you can just export the entire database to XML, remove the subform from one of the places using a text editor, and re-import the database. Much quicker for the most part.
Jake,
Dim doc1 as NotesDocument,
Dim doc2 as NotesDocument
you should use this form anyway, as in class declaration (eg public doc1 as NotesDocument)
you won't be able to use public doc1, doc2 as NotesDocument or similar too.
Cheers, Tom
Jake,
Working between Java and Lotuscript always throws problems like this for me as well.
private MyObject obj1, obj2, obj3;
This works fine in Java but as you saw not in lotusscript. I know the languages are obviously very different but it still takes me a while to get my head back into the groove of whatever I am programming!
Jason
@Stan: DUH, I know that, I know that, I know that. (untyped are variants) I have NO idea why I said 'strings'. Must have been a brain fog rolling in that day. Thanks for keeping me honest. :)
RE: "Not a Form" error
Most of the 'corrupted design -- now start over' experiences I have had in the past have been as a result of complicated arrangements of embedded subforms.
Now I use computed subforms in place of embeds almost anytime I use subforms and I find it to be much more stable.
(Loved the holiday story, by the way)
Always computed subforms in favour of regular subforms? Sounds like a great performance killer to me.
Subforms in general can slow things down a little; but I haven't seen that the performance difference with computed subforms is worth bothering about.
cheers.
What to do with the "Not a form" message?
If its not a form but a document, why is it registered under 'Forms' ?
Hi
Its an issue related to "Using Database" Document or "About database" document under database Resources.. So uncheck the "Show About database" property from database launch tab.