Tip

Dynamic Table

This script simulates a dynamic table on a form.
You can add, delete or modify rows in the table

The code below needs 5 fields ( A1, B1, C1, D1, E1 ) on the form.
The field properties are : Text, Calculated

In addition create 5 fields ( HA, HB, HC, HD, HE ) with properties: Text,
Calculated, Always hidden
Create 3 Buttons on the form ( Add Row, Delete Row, Modify Row )

Create a scipt library and copy the SCRIPT LIBRARY code
Create 4 agents and copy the AGENT code.

Create a form ("Diaolog Box") with a layout region
Create 5 fields in the layout region ( HA, HB, HC, HD, HE ) with properties:
Text, Editable

'==========================================================
' SCRIPT LIBRARY "SharedVariables"
'==========================================================
Option Public
Option Declare
Dim Session As NotesSession
Dim Workspace As NotesUIWorkspace
Dim DB As NotesDatabase
Dim UIDoc As NotesUiDocument
Dim Doc As NotesDocument

Sub Initialize

'Declare global object variables
Set Workspace = New NotesUIWorkspace
Set Session = New NotesSession
Set DB = Session.CurrentDatabase
Set UIDoc = Workspace.CurrentDocument
Set Doc = UIDoc.Document

End Sub

Sub ClearFields

Call UIDoc.FieldSetText("HA","")
Call UIDoc.FieldSetText("HB","")
Call UIDoc.FieldSetText("HC","")
Call UIDoc.FieldSetText("HD","")
Call UIDoc.FieldSetText("HE","")

End Sub

'==========================================================
' AGENT "AddFirstRow"
'==========================================================
'OPTIONS

Option Public
Option Declare
Use "SharedVariables"

'DECLARATION

Dim AField As Variant
Dim BField As Variant
Dim CField As Variant
Dim DField As Variant
Dim EField As Variant

Sub Initialize

Call GetCurrentFields() 'Get values of existing fields
Call ClearFields() 'Initialize hidden fields

If Workspace.DialogBox( "DialogBox", True,True, False, True, False,False,
"Enter New Characteristic") Then
Call SetTableFields
End If

Call UiDoc.Reload
Call UiDoc.Refresh

End Sub

Sub GetCurrentFields
AField = ExpandField(Doc.A1)
BField = ExpandField(Doc.B1)
CField = ExpandField(Doc.C1)
DField = ExpandField(Doc.D1)
EField = ExpandField(Doc.E1)
End Sub

Sub SetTableFields

AField = Doc.HA(0)
BField = Doc.HB(0)
CField = Doc.HC(0)
DField = Doc.HD(0)
Efield = Doc.HE(0)
Doc.A1 = AField
Doc.B1 = BField
Doc.C1 = CField
Doc.D1 = DField
Doc.E1 = EField

End Sub

Function ExpandField(Field As Variant) As Variant

Dim NewField() As String 'Array to temporarily store the new "expanded"
field.
Dim J As Integer 'Index counter for new field
Dim K As Integer 'Index counter for existing field.

Redim Newfield(0) 'dimension the newfield to one element only
NewField(0) = ""

'Return the expanded field.
Expandfield = newfield

End Function

'==========================================================
' AGENT "AddRow"
'==========================================================
Option Public
Option Declare
Use "SharedVariables"


Dim InsertionPoint As Integer
Dim AField As Variant
Dim BField As Variant
Dim CField As Variant
Dim DField As Variant
Dim EField As Variant

Sub Initialize

InsertionPoint = Cint(Trim(Session.GetEnvironmentString("EnvIP")))
Call GetCurrentFields() 'Get values of existing fields
Call ClearFields() 'Initialize hidden fields

If Workspace.DialogBox( "DialogBox", True,True, False, True, False,False,
"Enter New Characteristic") Then
Call SetTableFields
End If

Call UiDoc.Reload
Call UiDoc.Refresh

End Sub

Sub GetCurrentFields
AField = ExpandField(Doc.A1)
BField = ExpandField(Doc.B1)
CField = ExpandField(Doc.C1)
DField = ExpandField(Doc.D1)
EField = ExpandField(Doc.E1)
End Sub

Sub SetTableFields

'Using InsertionPoint as an index, plug the values returned from the
dialog box into the appropriate places in the respective "field" variants.

AField(InsertionPoint)

This was first published in November 2000

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.