Common Methods for Lotus Notes development

Source: Internet
Author: User
Tags odbc connection

Title: Lotus Notes common development methods
1. About appenditemvalue

Try the following simple example:

Dim ws as new notesuiworkspace

Dim uidoc as notesuidocument

Dim doc as notesdocument

Set uidoc = ws. currentdocument

Set doc=uidoc.doc ument

For I = 1 to 10

Call Doc. appenditemvalue ("myitem", I)

Next

Call Doc. Save (True, true)

ThisProgramIt is used to add 10 items to the current document. The names of all items are myitem, but the values range from 1 to 10. What are the results? After observing through debugging, we found that 10 items were added, all of which were named myitem, but the values were all 1! This is inconsistent with the help in notes. Help claims:

If the document already has an item called itemname $, appenditemva

Lue does not replace it.

Instead, it creates another item of the same name, and gives it th

E value you specify.

^

The results from 4.6 to 5.0 are the same.

Ii. Differentiate the foreground and background categories of notes

Because the use range of the two is different, you should pay attention to this when writing a program, especially when writing a proxy. If you add the following statement to the proxy running on the background server:

Dim ws as new notesuiworkspace

The agent running log reports the following error: unkown error.

3. Shared domains of notes and Ole

Notes provides a good function: Sharing domains. Notes uses a shared domain to exchange information with OLE applications. However, unless it is necessary to share information with the OLE application, we recommend that you choose to prohibit the sharing domain when designing the form. The author once created an author domain author in a form, and embedded the MS-WORD documentation in its RTF domain:

Call uidoc. creatobject ("mydoc", "word. document.8 ","")

Everything seems normal. However, when I changed the author domain author of notes (because I tried to control the modification of the Notes document through the author domain), because of the needs of the process, I changed it to two values, which are displayed in notes:

User1/co1/server1, user2/co1/server2

Modify the Word documents embedded in the RTF domain, exit, and save the changes. The result is incorrect. The notes error is: you are not the author of the document and cannot save it! Why? At that time, I used user1/co1/server1 to modify it! Later, after careful debugging, we removed the hidden attribute of author and observed that the author value became:

User1/co1/server1/co1/server2!

It turns out that word also has an author domain, which is also called author (which seems to be unchangeable). The author of word and the author of notes affect each other? I don't know), so it turns out this strange thing! The solution, of course, is to "Disable domain exchange" in the Notes form! (OLE applications have too many domains and it is unlikely to find out the names of these domains. So "prohibit domain exchange" should be the best way to solve such problems, I think)

Iv. Using notes to integrate OA applications and office to make up for notes Insufficiency

 

 

 

Sub entering (source as field)

Dim curws as new notesuiworkspace

Dim uidoc as notesuidocument

Set uidoc = curws. currentdocument

Lnflag = uidoc. fieldgettext ("docadd ")

If lnflag = 0 then

Call uidoc. fieldsettext ("docadd", "1 ")

Call uidoc. Createobject ("worddoc", "word.doc ument.8 ","")

End if

Exit sub

End sub

After submission, all modifications made to the Word document by the editor must be recorded and displayed. Therefore, the Word document must be changed to the revision status. In the submit button, write the following program:

Sub click (source as button)

Dim ws as new notesuiworkspace

Dim uidoc as notesuidocument

Set uidoc = ws. currentdocument

Dim curdoc as notesdocument

Set curdoc=uidoc.doc ument

Dim worddoc as notesembeddedobject

Dim wordapp as Variant

Call ws. editdocument (true)

Lnflag = uidoc. fieldgettext ("docadd ")

If lnflag = "1" then

Set worddoc = curdoc. embeddedobjects (0)

Set wordapp = worddoc. Activate (false)

Call worddoc. doverb ("Edit (& E )")

Wordapp. application. Visible = false

Wordapp. application. activedocument. trackrevisions = true

Wordapp. application. activedocument. showrevisions = true

Call wordapp. application. activedocument. Save

Call wordapp. application. Exit

End if

Call uidoc. Save

Call ws. editdocument (false)

End sub

The procedure for modifying the Word document to the revised state can be changed:

Set wordapp = uidoc. GetObject ("worddoc ")

Wordapp. application. Visible = false

Wordapp. application. activedocument. trackrevisions = true

Wordapp. application. activedocument. showrevisions = true

Call wordapp. application. activedocument. Save

Access through the GetObject method of uidoc.

 

 

However, you should pay attention to the spelling correctness when accessing through the OLE object, especially when you can specify the OLE object name (rather than the file name) to create the object, pay attention to the correctness of the OLE object name.

 

 

. Otherwise, the error is unpredictable. For example, in the entering event of the RTF domain, modify the statement of creating an object as follows:

Call uidoc. Createobject ("worddoc", "word.doc ument.8 ","")

Change to: Call uidoc. Createobject ("worddoc", "word.doc ument ","")

OLE objects can still be created. Everything seems to be normal. However, if you access the document through embeddedobject during the execution and submission

 

(False) error: the object cannot be stored.

If you use the GetObject method of uidoc for access

Error When wordapp. application. activedocument. trackrevisions = true: the document is not activated.

5. Use appendtotextlist

Appendtotextlist adds text list items. The usage is as follows:

Dim rtitem as notesitem

Dim uidoc as notesuidocument

Dim ws as notesuiworkspace

Dim curdoc as notesdocument

Set uidoc = ws. currentdocument

Set curdoc=uidoc.doc ument

Set rtitem = curdoc. getfirstitem ("Authors ")

Lcreader = curdoc. getitemvalue ("readers ")

For I = 0 to ubound (lcreader)

Call rtitem. appendtotextlist (lcreader (I ))

Next

In the above example, the value of multi-value readers is appended to another multi-value authors one by one. There is another way to achieve this, that is, through the getitemvalue method of notesdocument

 

Put the values of the two fields into two arrays, and then merge the two arrays into a new array. Call the replaceitemvalue method of notesdocument to assign the values of the new array

 

 

Authors. But obviously, This method requires a much larger amount of programming. Some may say why the field settext of notesuidocument does not need to be added by adding strings.

 

Is the string assigned to the corresponding domain? According to the Notes description and corresponding help, this should be acceptable (of course, the delimiter used between two strings is used to design the domain

 

 

Open ). But in fact, this method is extremely unreliable! When the values of both fields are names, the results of such operations cannot be guaranteed. Notes has its own location for the name field

 

But how does it convert the name displayed on the front-end to the name displayed on the back-end? I'm afraid no one can make it clear. I have tried this method. When there is only one or two values, this operation is generally not

 

 

 

Wrong; but when there are too many values (I tried about 7), sometimes everything works normally, sometimes the error is incredible: Notes treats the entire string as a value! It's totally irrational.

 

Multi-value delimiter of the domain! Note that the Save method of notesdocument is not required, and the changes made in the previous example are still valid. The notesitem variable should be a pointer to the corresponding document

 

 

 

(I guess ).

Vi. Notes ODBC support Defects

A Notes does not support the stored procedure, a pre-storage program for back-end databases (such as Oracle), even in the new version 6.2. It does not actually work.

B. If there are multiple SQL statements in an ODBC connection, the following error occurs: Too extends cursor. Although your SQL statement does not include cursor at all. Lotus claimed that the bug had been fixed in versions 4.6 and later, but the answer was true.

VII. Notes Array

A defines an array

There are two methods: dim and redim.

Dim defines arrays of fixed numbers and data types, while redim defines different types of data, or the number is not fixed. Compare the following examples. Examples:

Dim myarray (5, 2) as string redim myarray (5, 2) as string

The former is incorrect while the latter is valid. Example:

N = 10 N = 10

Dim myarray (n) as string redim myarray (n, 2) as string

In addition, redim can also define undefined arrays, such as redim myarray (10)

Number of B Arrays

The subscript specified when an array is defined by dim or redim indicates the maximum subscript allowed to access the array, but not the number of the array. In fact, the number of one-dimensional arrays is always equal (

 

Large subscript + 1). The subscripts are accessed one by one from 0.

For example, there are 6 array elements defined by dim myarray (5) as string: myarray (0 ),

Myarray (1), myarray (2), myarray (3), myarray (4), and myarray (5 ).

Another example is: redim thisarray () as string actually defines a two-dimensional array (2 + 1) * (5 + 1) = 1 8.

In this case, it is not necessary to define an array with only one element? The answer is: no.

As mentioned above, the array defined by redim thisarray (1) actually has (1 + 1) array elements, but similar to the syntax of redim thisarray (0, notes also thinks it is wrong. So,

 

 

An array with only one array element cannot be defined. In fact, the above is only about its default situation. In fact, to define an array, you can define the starting and ending times of the subobject to define the number of arrays.

 

 

To the start and end numbers of the following mark. For example, redim thisarray (1980 to1990) defines an array containing 11 elements with subscripts ranging from 1980 to 1990.

C about ubound Functions

Ubound returns the maximum subscript of a one-dimensional array, rather than the number of elements. For example, if Dim myarray (5) is as integer, the value returned by ubound (myarray) is 5 rather than 6.

 

 

Ubound can also be applied to two-dimensional arrays. When applied to a two-dimensional array, it returns the maximum value of the first submark.

For example, dim myarray (6, 3) as integer,

Then the value returned by ubound (myarray) is 6, not 7, not 18 (6*3 = 18 ).

To return the maximum value of the second subobject, use ubound (myarray, 2 ).

Opposite to ubound is another function: lbound, which returns the minimum subscript of the array. Similar to ubound, lbound (myarray, 2) returns the most

 

 

Small value. Therefore, the number of elements in the one-dimensional array myarray is ubound (myarray)-lbound (myarray) + 1, while the number of elements in the two-dimensional array is:

(Ubound (myarray)-lbound (myarray) + 1) * (ubound (myarray, 2)-lbound (myarray, 2) + 1)

Multi-dimensional array.

D. Return the Array Function.

You can define a function to return an array. When declaring a function, you only need to declare it to return the variant type.

. For example:

Function db_string (byval fdname as string) as Variant

Fdnum = Len (fdname)

Redim lcarray (fdnum, 2) as string

Lcarray (0, 0) = "thisstr"

Lcarray (0, 1) = ","

Lcarray (0, 2) = ","

......

Db_string = lcarray' causes the function to return the value of the array lcarray.

End Function

Call a function in the following way:

Thisstring = "aaaaaaaa"

Dim thisarray as Variant

Thisarray = db_string (thisstring)

Print thisarray (0, 0)

8,

ODBC in notes :( ls: Do)

A: several classes that need to be mastered when writing ODBC programs using Lotus Script: odbcconnection, odbcq

Uery, and

Odbcresultset. The common practice is:

Set con = new odbcconnection

Dim dbqry as new odbcquery

Dim dbresult as new odbcresultset

Ret = con. connectto (dbsourcename, dbusername, dbpass)

If con. isconnected = false then

Ret1 = msgbox ("the database cannot be connected, please contact the system administrator", 48, "prompt message ")

Odbc_insert =-2

Exit Function

End if

Dbqry. SQL = "select * From thistable where thistable. ID = thisid"

Set dbqry. Connection = con

Set dbresult. query = dbqry

Dbresult.exe cute

% Rem

Access the relational database through dbresult: value, update the database

% End REM

Status = dbresult. Close (db_commit)

Ret = con. Disconnect

B can update data (insert, delete, and modify) through odbcresultset in two ways. One way is to attach odbcqry. SQL as a query statement, and then pass

 

 

Odbcresultset class addrow, updaterow, deleterow, setvalue and other methods to update relational databases. For example, add a record to thistable and assign the string type

 

 

The value of field1 is test:

Set con = new odbcconnection

Dim dbqry as new odbcquery

Dim dbresult as new odbcresultset

Ret = con. connectto (dbsourcename, dbusername, dbpass)

If con. isconnected = false then

Ret1 = msgbox ("the database cannot be connected, please contact the system administrator", 48, "prompt message ")

Odbc_insert =-2

Exit Function

End if

Dbqry. SQL = "select * From thistable where 1 = 0"

Set dbqry. Connection = con

Set dbresult. query = dbqry

Dbresult.exe cute

Call dbresult. addrow

Call dbresult. setvalue ("field1", "test ")

Call dbresult. updaterow

Status = dbresult. Close (db_commit)

Ret = con. Disconnect

Because the updaterow method is only valid for odbcresultset with only one record (an error is reported when multiple record entries exist), there is only one condition in SQL that is never valid: 1 = 0,

 

Make sure that there is only one odbcresultset before updaterow after addrow is executed. Another method is to directly update the database using SQL statements. Its advantage is that it can be updated at a time.

 

 

Multiple transactions, and more flexible, the disadvantage is that the data type conversion between Domino and the background relational database must be considered. The following example shows the same effect as the previous example.

Set con = new odbcconnection

Dim dbqry as new odbcquery

Dim dbresult as new odbcresultset

Ret = con. connectto (dbsourcename, dbusername, dbpass)

If con. isconnected = false then

Ret1 = msgbox ("the database cannot be connected, please contact the system administrator", 48, "prompt message ")

Odbc_insert =-2

Exit Function

End if

Dbqry. SQL = "insert into thistable (thisid) values ('test ')"

Set dbqry. Connection = con

Set dbresult. query = dbqry

Dbresult.exe cute

Status = dbresult. Close (db_commit)

Ret = con. Disconnect

C. About type conversion

Data type conversion is usually required when data is updated using odbcresultset. You can update the database without type conversion by using the method in the preceding method. The conditions are as follows:

 

The corresponding field value in the Notes form cannot be blank (because if any field value in notes is empty, its data type is always string and its value is null ). How to implement it? Example of method 1

 

In

Call dbresult. setvalue ("field1", "test") transformation is as follows:

Ltmp = Doc. getitemvalue ("doc_field1 ")

Call dbresult. setvalue ("field1", ltmp (0 ))

Doc_field1 is the notes domain name corresponding to the relational database Field field1. In this way, you can change the corresponding background relational database through the domain name. Update in method 2

 

 

Database, type conversion is required. You can use the data type of the fields in the foreground notes to determine the SQL statements that can be correctly executed. For example, for example, the statement type, before the value

 

It is enclosed in single quotation marks. Numeric values are not required. But how to obtain the data type? You can use the type attribute of notesitem to access the data type of the entries returned by notesdocument, for example, plain type.

 

 

1280, 768, 1024, and so on. However, when the corresponding field value is null, notesitem. Type will always return 1280 (I .e., signature type), regardless

 

Whether the field value type is numeric or date. Another method is to convert data types and generate SQL statements that can be correctly executed by using the data types of relational databases in the background.

 

The odbcresultset. fieldnativedatatype method returns the corresponding field types of the background data type, such as SQL _char, SQL _integer, and SQL _timestamp.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.