Tip

Working with a "native grid" in a Notes form

This is a useful script function when working with a "grid" where you can calc values and/or get and set values in several types of applications using a "grid." This code works in a Notes client but it is very easy to use the same scheme in JavaScript.

1. Create a table with four columns and four rows. Put a field in each cell and name the fields A,B,C,D.

2. Create a table with four columns and one row. Copy and paste the fields in the top table into the table. The first row starts with A_1 and the last row with A_4. The next column is B_1...etc. This one only works when you make a copy of the row in the top table. Otherwise, the names of the fields are A_1_1, B_2_2 and that will not work.

2a. Now you can hide the top table. However, do not remove the table. It is very useful if you want to change the properties for a field. You can do it in one place then copy and paste again.

3. Create an agent and paste the code into it. Then save the agent manually from the action menu and run once.

4. Create an action. Name it and from simple action, choose run agent.

You can not calc values in a very simple way in a grid. Write the values in the first three columns and run the agent by pressing the action button.

'Global declaration
Dim ColumnCounter(1 To 4) As String
Dim Uidoc as notesuidocument


Sub Initialize
Dim workspace As New notesuiworkspace
Dim i As Integer	

Set uidoc = workspace.currentdocument

Call setColumnNames

For i = 1 To 4
 Call setAndCalcFields(i)
Next i
End Sub



Sub SetColumnNames()
 ColumnCounter(1) = "A"
 ColumnCounter(2) = "B"
 ColumnCounter(3) = "C"
 ColumnCounter(4) = "D"
End Sub



Sub setAndCalcFields(row As Integer)
Dim x As Integer	
Dim FieldName As String
Dim sum As Double
On Error Resume Next
 For x = 1 To 3
  fieldName =	ColumnCounter(x) + "_" +Trim(Str(row))
  sum = sum + Cdbl(uidoc.FieldGetText(FieldName))
 Next x
  fieldName =	ColumnCounter(4) + "_" +Trim(Str(row))
  Call uidoc.FieldSetText(fieldName, Str(sum))
End Sub

This was first published in June 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.