'The Scripted Object Component currently limits the number 'of input and output ports to the maximum of four. Const InOutPorts = 4 ReDim InputStartingCell(InOutPorts), OutputCellRange(InOutPorts) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Edit the cell and range strings in the definitions below 'to match the configuration of your inputs and outputs. InputStartingCell(0) = "A1" InputStartingCell(1) = "B2" InputStartingCell(2) = "B4" InputStartingCell(3) = "A1" OutputCellRange(0) = "B2..C4" OutputCellRange(1) = "C3..D3" OutputCellRange(2) = "A1..A1" OutputCellRange(3) = "A1..A1" 'Do not edit below this line. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub LotusWkbEvent_Start() 'Set the Source property of VBScript's built-in error object Err, 'in case an error is encountered. Err.Source = "Lotus 1-2-3 Scripted Object Inside Mathcad" End Sub Sub LotusWkbEvent_Exec(Inputs,Outputs) 'The string constant BIGRANGE is supposed to cover a big range. 'All user ranges referenced by this Component must fall within BIGRANGE. Const BIGRANGE = "A1..Z100" Dim r, c, iCount, RowSpan, ColumnSpan 'Get data from each input port ' For iCount=0 to Inputs.Count-1 Set inp = Inputs(iCount) inpVal = inp.Value If inp.IsComplex Then ComplexInputError 'Starting cell as a one-cell range object Set StartingCellRange = Ranges.Item(InputStartingCell(iCount)) 'Iterate through the rows and columns and assign 'appropriate input values to the appropriate spreadsheet cells. ' For r=0 To inp.Rows-1 For c=0 To inp.Cols-1 'Debugging message - uncomment if needed 'MsgBox "Row=" & r & " Col=" & c & " Val=" & inpVal(r,c) 'Current cell as a one-cell range object Set CurCellRange = Ranges(BIGRANGE).Cell(StartingCellRange.StartRow + r, StartingCellRange.StartColumn + c) CurCellRange.Contents = inpVal(r,c) Next Next Next 'Done processing all inputs 'Assign data to each output port ' For iCount=0 to Outputs.Count-1 Set outp = Outputs(iCount) 'Output cell range object Set OutputRange = Ranges.Item(OutputCellRange(iCount)) RowSpan = OutputRange.EndRow - OutputRange.StartRow ColumnSpan = OutputRange.EndColumn - OutputRange.StartColumn 'Declare VB-style array corresponding to the spreadsheet range 'to be sent to the component's output port. ReDim outval(RowSpan, ColumnSpan) 'Iterate through the rows and columns of the spreadsheet range 'and assign appropriate cell values to the appropriate outval array elements. ' For r=0 To RowSpan For c=0 To ColumnSpan 'Current cell range object Set CurCellRange = Ranges(BIGRANGE).Cell(OutputRange.StartRow + r, OutputRange.StartColumn + c) 'Debugging message - uncomment if needed 'MsgBox "Row=" & r & " Col=" & c & " Val=" & CurCellRange.CellValue outval(r,c) = CurCellRange.CellValue Next Next 'Pass the final outval array to the current output port. outp.Value = outval Next End Sub Sub LotusWkbEvent_Stop() REM TODO: Add your code here End Sub 'ERROR PROCESSING PROCEDURES 'Error numbers from 0 to vbObjectError are reserved by VBScript; 'user-defined errors can start after that. 'User error number 17 has been chosen for this script. Sub ComplexInputError() Err.Description = "Lotus 1-2-3 does not know how to deal with complex inputs." & Chr(10) & "Please make sure that all your inputs are real." Err.Raise(vbObjectError + 17) End Sub