LOTUSSCRIPT/COM/OLE CLASSES
Examples: InViewEdit event
1. This InViewEdit event is for a view where all the editable columns are Text and are processed the same. The user edits a column entry. Your code validates the edited column entry (it cannot be an empty string). When the user clicks out of the editable column entry or tabs out of all the editable column entries for the row, your code writes the editable column entries in the ColProgName and ColumnValue arrays to the underlying document.
Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
%REM
In this view, the programmatic name of each editable column
is the same as the name of the field whose value it holds.
All the fields for the editable columns are simple Text.
Each editable column gets the same processing.
%END REM
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim caret As String
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use in Release 6.0
Case VALIDATE_REQUEST
REM Cause validation error if user tries to exit column with no value
If Fulltrim(Columnvalue(0)) = "" Then
Messagebox "You must enter a value",, "No value in column"
Continue = False
End If
Case SAVE_REQUEST
REM Write the edited column view entries back to the document
For i = 0 To Ubound(Colprogname) Step 1
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create "Form" item
REM Write column values to the new document
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
For i = 0 To Ubound(Colprogname) Step 1
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub
2. This InViewEdit event is for a view with two editable columns, one Text and one Numeric. The code must distinguish between the columns because the processing for each differs in some respects.
Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
%REM
This view has two editable columns: one Text and one Numeric.
The programmatic name of each editable column
is the same as the name of the field whose value it holds,
but the processing for each column is different.
%END REM
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim caret As String
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use for Release 6.0
Case VALIDATE_REQUEST
REM Write message and cause validation error if ...
Select Case Colprogname(0)
Case "FieldText"
REM ... user tries to exit text column with no value
If Fulltrim(Columnvalue(0)) = "" Then
Messagebox "You must enter a value",, "No value in column"
Continue = False
End If
Case "FieldNumeric"
REM ... value in numeric column is non-numeric or negative
If Isnumeric(Columnvalue(0)) Then
If Cint(Columnvalue(0)) < 0 Then
Messagebox "Value must be greater than 0",, "Negative value"
Continue = False
End If
Else
Messagebox "Value must be numeric",, "Non-numeric value"
Continue = False
End If
End Select
Case SAVE_REQUEST
REM Write the edited column view entries back to the document
For i = 0 To Ubound(Colprogname) Step 1
Select Case Colprogname(i)
REM Write text entry back to document
Case "FieldText"
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
REM Write converted numeric entry back to document
Case "FieldNumeric"
Call doc.ReplaceItemValue(Colprogname(i), Cint(Columnvalue(i)))
End Select
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create "Form" item
REM Write column values to the new document
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
For i = 0 To Ubound(Colprogname) Step 1
Select Case Colprogname(i)
REM Write text entry to document
Case "FieldText"
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
REM Write converted numeric entry to document
Case "FieldNumeric"
Call doc.ReplaceItemValue(Colprogname(i), Cint(Columnvalue(i)))
End Select
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub
3. This InViewEdit event is like the first example except that the programmatic names of the columns are not the same as the items associated with the column. Therefore, the code must examine each column and process the correct item.
Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
%REM
In this view, all the fields for the editable columns are simple Text.
Each editable column gets the same processing.
But the programmatic names of the columns are not the same
as the field names, so you have to case the names.
%END REM
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim caret As String
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use in Release 6.0
Case VALIDATE_REQUEST
REM Cause validation error if user tries to exit column with no value
If Fulltrim(Columnvalue(0)) = "" Then
Messagebox "You must enter a value",, "No value in column"
Continue = False
End If
Case SAVE_REQUEST
REM Write the edited column view entry back to the document
For i = 0 To Ubound(Colprogname) Step 1
Select Case Colprogname(i)
Case "ColumnOne"
Call doc.ReplaceItemValue("FieldOne", Columnvalue(i))
Case "ColumnTwo"
Call doc.ReplaceItemValue("FieldTwo", Columnvalue(i))
Case "ColumnThree"
Call doc.ReplaceItemValue("FieldThree", Columnvalue(i))
End Select
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create "Form" item
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
For i = 0 To Ubound(Colprogname) Step 1
REM Write the edited column view entry back to the document
Select Case Colprogname(i)
Case "ColumnOne"
Call doc.ReplaceItemValue("FieldOne", Columnvalue(i))
Case "ColumnTwo"
Call doc.ReplaceItemValue("FieldTwo", Columnvalue(i))
Case "ColumnThree"
Call doc.ReplaceItemValue("FieldThree", Columnvalue(i))
End Select
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub
4. This InViewEdit event is for a view with one editable column so only the first element of the ColProgName and ColumnValue arrays has to be processed. The column is for a list box field so the verification code forces the user to enter one of the values from the list box.
Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
%REM
This view has one editable column, which is for a list box item.
%END REM
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim ws As New NotesUIWorkspace
Dim caret As String
REM Define allowed values for list box
Dim elements(4) As String
elements(0) = "red"
elements(1) = "green"
elements(2) = "blue"
elements(3) = "yellow"
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use for Release 6.0
Case VALIDATE_REQUEST
REM Cause validation error if user tries to exit column with no value
If Fulltrim(Columnvalue(0)) = "" Then
Messagebox "You must enter a value",, "No value in column"
Continue = False
End If
REM Or enters a value that is not in the list box
Dim flag As Boolean
flag = False
Forall element In elements
If Lcase(element) = Lcase(Columnvalue(0)) Then
flag = True
Exit Forall
End If
End Forall
If Not flag Then
Dim msg As String
Forall element In elements
msg = msg & element & Chr(10)
End Forall
Messagebox msg,, "Value must be one of the following"
continue = False
End If
Case SAVE_REQUEST
REM Write the edited column view entry back to the document
Call doc.ReplaceItemValue(Colprogname(0), Columnvalue(0))
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create "Form" item
REM Write column value to the new document
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
Call doc.ReplaceItemValue(Colprogname(0), Columnvalue(0))
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub
5. This InViewEdit event is for a view with one editable column that represents its value as an icon. The code processes the field by writing one of two values to the document represented by the row. This has the effect of toggling two icons.
Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
%REM
This view has one editable column, which is for a list box item.
%END REM
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim ws As New NotesUIWorkspace
Dim caret As String
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use for Release 6.0
Case VALIDATE_REQUEST
REM Not used for icon columns
Case SAVE_REQUEST
REM Toggle value and write back to the document
If doc.GetItemValue(Colprogname(0))(0) = "OK" Then
Call doc.ReplaceItemValue(Colprogname(0), "NotOK")
Else
Call doc.ReplaceItemValue(Colprogname(0), "OK")
End If
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create "Form" item
REM Write column value to the new document
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
Call doc.ReplaceItemValue(Colprogname(0), "OK")
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub
See Also
InViewEdit event
Glossary
Feedback on
Help
or
Product Usability
?
Help on Help
All Help Contents
Glossary