Lotus Notes Development Common Method

xiaoxiao2021-03-06  60

First, 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.document

FOR i = 1 to 10

Call Doc.AppendItemvalue ("MyItem", i)

NEXT

Call Doc.save (True, True)

This program is used to add 10 items to the current document, named myItem, but the value ranges from 1 to 10. How is the result? Observation in the form of debugging, found: There is indeed 10 items, named myitem, but the value is 1! This does not match the help in Notes. Declaration in the help:

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.

^^^^^^^^^^^^^^^^^^^^^

From 4.6 to 5.0 results.

Second, distinguish NOTES's front desk class and background class

Since the use range of the two is not a way, pay attention to this when writing the program, especially when writing agency. If you add a sentence in the proxy running in the background server:

DIM WS AS New NotesuiWorkspace

Agent Run Log error: Unkown Error.

Third, shared domain about Notes and OLE

Notes provides a good feature: shared domain. NOTES uses a shared domain to exchange each other information with the OLE application. However, unless it is necessary to share information with the OLE application, it is recommended to select: Disable shared domains when designing a form. The author has created an author domain Author in a form, and embedded in the MS-Word document in its RTF field:

Call Uidoc.creatobject ("MyDoc", "Word.Document.8", "" "

It seems that everything is normal. But when I changed the authority of Notes Author's Author Domain Author (because the author tried to change the modification of the Notes document to achieve the purpose of the process control), because the process needs, I turned it into two values, in Notes The display is shown in:

User1 / Co1 / Server1, User2 / CO1 / Server2

Then modify the Word document embedded in the RTF domain, then exit, save. The results have appeared, Notes error: You are not the author of the document, can not save! what reason? At that time, I was clearly modified with USER1 / CO1 / SERVER1! Later, carefully debug, remove the Hide property of Author's hidden property, and observe it carefully. It is found that as long as the Word document embedded in the RTF domain is activated, the value of Author's value turns into:

USER1 / CO1 / Server1 / Co1 / Server2!

It turns out that Word also has an author domain. The name is also called Author (seemed to be able to change) the author's author and notes' author interaction (how to influence? I don't know), so I changed the strange thing! Solution, of course, it is to put the Notes form "forbidden domain exchange"! (OLE application has too many domains, wanting to clarify the names of these domains, so it seems unobsive. So "forbidden domain exchange" should be the best way to solve such problems, stealing) four, use Notes integration OA Application, office make up Notes insufficient

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.Document.8", "" "

END IF

EXIT SUB

End Sub

When submit, you must record and display all modifications to the Word document, so you have to change the Word document to the revised state. In the submit button, write the following procedure:

Sub Click (Source As Button)

DIM WS AS New NotesuiWorkspace

DIM Uidoc as Notesuidocument

Set uidoc = ws.currentdocument

Dim Curdoc as NotSdocument

SET CURDOC = Uidoc.Document

DIM WordDoc as NotSembeddedObject

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.trackRevision = 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 above program that modifies the Word document is a revised state, is actually changed to:

SET WORDAPP = Uidoc.getObject ("WordDoc")

Wordapp.Application.visible = false

Wordapp.Application.activeDocument.trackRevisions = truewordapp.Application.activeDocument.showrevisions = true

Call wordapp.Application.activedocument.save

That is, access it through the Uidoc's getObject method.

However, when accessible via OLE object, pay attention to the correctness of spelling, especially when you indicate the OLE object name (rather than file name), pay more attention to the correctness of the OLE object name. Otherwise, it is difficult to expect. For example, in an Entering event in the RTF domain, create an object statement as follows:

Put: Call Uidoc.createObject ("WordDoc", "Word.Document.8", "" "

Change to: Call Uidoc.createObject ("WordDoc", "Word.Document", "")

OLE objects can still be created, everything seems to be normal. However, when the submission is performed, if the document is accessed by EmbedDedObject, an error occurs when SET WORDAPP = WordDoc.Activate (false): You cannot store the object.

If you are accessible through the Uidoc getObject method,

Wordapp.Application.activeDocument.trackRevisions = true error: No documentation is activated.

5. Using appendtotextList

AppendtotextList Add a text list item. The method is as follows:

DIM RTITEM AS NotesItem

DIM Uidoc as Notesuidocument

DIM WS AS NotesuiWorkspace

Dim Curdoc as NotSdocument

Set uidoc = ws.currentdocument

SET CURDOC = Uidoc.Document

Set RTITEM = CURDOC.GETFIRSTITEM ("Authors")

LcReader = Curdoc.getItemValue ("Readers")

For i = 0 to Ubound (LcReader)

Call RTITEM.AppendtotextList (LcReader (i))

NEXT

The above example adds the value of the multi-value domain readers to another multi-value domain authors. To achieve this, there is another way, namely: Bringing the value of the two domains into two arrays through the NOTESDocument's GetItemValue method, combined with two arrays into a new array, by calling NotesDocument's ReplaceItemValue method Assign the value of the new array to Authors. But it is apparent that this method is much larger. Some people may say, why don't you use the string to add, re-pass NOTESUIDOCUMENT Field SetText gives the added character to the corresponding domain? Press NOTES's instructions and their corresponding help, this should be possible (of course, the separator between the two strings applied to the designation domain). But in fact, this method is extremely unreliable! In particular, when the values ​​of the two domains are named, it is really unable to ensure that the results produced in such operations are. Notes has their own processing methods for the name domain, but how do it convert the names displayed in the front desk into the name of the background? I am afraid that no one can get it clear. I have tried this method. This kind of operation is generally not wrong when there is only one or two values; but when the value is more (there are about 7 or so), sometimes everything is normal, sometimes incurred: Notes actually uses the entire string as a value ! It actually did not pay a multi-value separator of the domain! It is also important to note that the changes made in the previous example are still valid through the Save method of NotesDocument. The NOTESITEM variable should be a pointer to the corresponding document (I guess). 6. Notes ODBC support defects

A Notes Unable to support the background procedure of the background database (such as Oracle), even if the new version of 6.2 is true. Although helping to claim to have a function of running the background database SP, it doesn't work.

B If there are multiple SQL in an ODBC Connection, it will be wrong: Too Many Cursor. Although your SQL statement does not contain Cursor. Lotus claims to be in 4.6 and later, this BUG has been resolved, but the answer is indeed.

VII, NOTES array

A definition array

There are two ways: DIM and REDIM.

DIM defines an array of fixed numbers and data types; while REDIM is different, it can define different types of data, or define a number of data. Compare the following examples. Examples of all legitimate:

DIM MyArray (5, 2) AS STRING Redim MyArray (5, 2) AS String

Example for the former and the latter legal example:

n = 10 n = 10

DIM MyArray (N) AS String Redim MyArray (n, 2) AS STRING

In addition, Redim can also define an unmissive type array, such as Redim MyArray (10)

B array number

The subscript specified when the array is defined in DIM or Redim, indicating the maximum subscript allowed when accessing the array, is not the number of the array. In fact, the number of one-dimensional number of groups is always equal to (maximum subscript 1), and when the access is accessed from 0, it will be accessed from 0.

For example: DIM MyArray (5) AS String defined array element has 6 elements, namely: MyArray (0),

MyArray (1), MyArray (2), MyArray (3), MyArray (4), MyArray (5).

Another example: Redim ThisArray (2, 5) AS String actually defines a 2D array of (2 1) * (5 1) = 1 8. So, then, can I define an array with only one element? The answer is: No.

As mentioned earlier, the array defined by Redim ThisaRray actually has (1 1) array element, but similar to: Redim ThisaRray (0) syntax, Notes is considered to be wrong. So, you cannot define an array of only one array element. In fact, it is just its default condition. In fact, the definition array can achieve the start number of the defined array by defining the subscript of the subscript. For example: Redim ThisaRray (1980 to1990) defines an array containing 11 elements that subscribe from 1980 to 1990.

C About Ubound function

Ubound returns the maximum subscript of a one-dimensional array, not the number of elements. For example: DIM MyArray (5) AS INTEGER, then the value returned by uBound (MyArray) is 5, not 6. Ubound can also be applied to a two-dimensional array. When applied to a two-dimensional array, it returns the maximum value of the first subscript.

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 subscript, use: Ubound (MyArray, 2).

Corresponding to Ubound is another function: lbound, which returns the minimum subscript of the array. Similar to Ubound, LBound (MyArray, 2) returns the minimum value of the second subscript of the array MyArray. So, accurately, the number of elements of one-dimensional array MyArray is: ubound (myarray) 1, and the number of elements of the two-dimensional array is:

(Ubound (MyArray) 1) * (Ubound (MyArray, 2) -lbound (MyArray, 2) 1)

The multidimensional array is pushed accordingly.

D Returns the function of array

You can define a function that returns an array. As long as the function is declared to return to the Varian type

. Such examples:

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 'Make the function returns the value of the array LCARRAY

END FUNCTION

When calling a function, call:

Thisstring = "aaaaaaa"

Dim ThisaRray As Variant

ThisaRray = db_string (thisstring)

Print ThisaRray (0, 0)

Eight,

NOTES ODBC: (Ls: DO)

A Several classes that need to be mastered when using LotusScript to write an ODBC program: ODBCCONNECTION, ODBCQ

Uery, with

ODBCRESULTSET. Usually: 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 ("Database Unable to Connect, Contact System Administrator", 48, "Tips")

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.EXECUTE

% REM

Accessing relationship database through DBRESULT: Take the value, update the database

% END REM

Status = dbResult.close (db_commit)

Ret = con.disconnect

B Update data (insert, delete, modify) through ODBCRESULTSET, can have two ways. In a way, the relational database is updated to the odbcqry.sql to query statements, and then can update the relational database over the ODDROW, UPDATEROW, DELETEROW, and SETVALUE of the ODBCRESULTSET class. Such as the following example, add a record for thisTable, and assign the value of the character string field Field1 as Test:

Set con = New ODBCCONNECCONNECTION

DIM DBQRY As New ODBCQUERY

DIM DBRESULT AS New ODBCRESULTSET

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

If Con.isconnected = False Then

Ret1 = msgbox ("Database Unable to Connect, Contact System Administrator", 48, "Tips")

ODBC_INSERT = -2

EXIT FUNCTION

END IF

Dbqry.sql = "SELECT * from thisTable where 1 = 0"

SET DBQRY.CONNECTION = Con

Set dbresult.query = dbqry

DBRESULT.EXECUTE

Call DBRESULT.ADDROW

Call DBResult.setValue ("Field1", "Test")

Call dbresult.Updaterow

Status = dbResult.close (db_commit)

Ret = con.disconnect

Since the Updaterow method only has an ODBCRESULTSET that contains only one record (more writing), there is only one condition that is never set up in the conditions in SQL: 1 = 0 to ensure ODBCRESULTSET before Updaterow after executing AddROW There is only one in the middle. Another way is to update the database directly with the SQL statement. It is the benefit of updating multiple pens at a time, and more flexible, the bad place is to consider the conversion between Domino and the background relational database. As the following example, the same effect as the above example can be achieved.

Set con = New ODBCCONNECTIONDIM DBQRY AS New ODBCQUERY

DIM DBRESULT AS New ODBCRESULTSET

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

If Con.isconnected = False Then

Ret1 = msgbox ("Database Unable to Connect, Contact System Administrator", 48, "Tips")

ODBC_INSERT = -2

EXIT FUNCTION

END IF

dbqry.sql = "Insert Into thisTable (thisid) Values ​​('Test')"

SET DBQRY.CONNECTION = Con

Set dbresult.query = dbqry

DBRESULT.EXECUTE

Status = dbResult.close (db_commit)

Ret = con.disconnect

C about type conversion

Type conversion is usually necessary to update the data by ODBCRESULTSET. Updating the database by the method in the above-described way can update the database without the type conversion, the condition is: the corresponding domain value in the Notes form cannot be empty (because any domain value in Notes is empty, its data type is always String, the value is empty string). How to achieve? In the example of the way

Call DBRESULT.SETVALUE ("Field1", "TEST") is transformed as follows:

LTMP = Doc.getItemValue ("DOC_FIELD1")

Call DBResult.setValue ("Field1", LTMP (0))

Where doc_field1 is a Notes domain name corresponding to the relational database field Field1. This is transformed so that the corresponding background relational database can be changed through the domain name. Update the database by the above-described manner, you want to perform type conversion. You can judge the data type of the front desk NOTES to determine the SQL statement that can be performed correctly, for example: character type, adding single quotes before and after generating; numerical type, no need. But how do I get the data type? Accessing the IOTESDocument's entry data type, such as: character type, return 1280; numerical type, return 768, return 1024, and so on. However, when the corresponding domain value is empty, NOTESITEM.TYPE will always return 1280 (ie, word type), regardless of the actual domain value type value or date. There is also a method for type conversion, generating the SQL statement that can be performed correctly through the data type of the background relational database. OdbcResultSet.fieldnativeDataType method Returns the corresponding field type of the background data type, such as SQL_CHAR, SQL_INTEGER, SQL_TIMESTAMP, and more.

转载请注明原文地址:https://www.9cbs.com/read-90111.html

New Post(0)