Vamos la insira no projeto o componente msscript.ocx
num módulo insira o codigo
Public GlobalMatriz As New matriz
Public idxFormula As Long
Public Script As Variant
Sub addCode(i As Integer, j As Integer)
Dim evals As String
Dim functions As String
Dim codeText As String
Dim b As String, c As String
Dim soma As String
'atraves de controles option verifica tipo de operação matematica
If Form2.chkSoma Then
evals = "valor1=" & GlobalMatriz.formula(i, j) & vbCrLf
evals = evals & "valor2=" & GlobalMatriz.formula(i - 1, j) & vbCrLf
evals = evals & "Form2.grd.TextMatrix(" & i + 1 & "," & j & ")= valor1 + valor2" & vbCrLf
ElseIf Form2.chkMult Then
evals = "valor1=" & GlobalMatriz.formula(i, j) & vbCrLf
evals = evals & "valor2=" & GlobalMatriz.formula(i - 1, j) & vbCrLf
evals = evals & "Form2.grd.TextMatrix(" & i + 1 & "," & j & ")= valor1 * valor2" & vbCrLf
End If
codeText = "Sub Eval_All" & vbCrLf _
& evals _
& vbCrLf _
& "End Sub" & vbCrLf _
& functions
'MsgBox codeText
' On Error Resume Next
Script.Language = "VBScript"
Script.Reset
Script.AddObject "Form2", Form2, True
Script.addCode codeText
Script.Run "Eval_All"
Exit Sub
If Err Then
MsgBox Script.Error.Description & "In line " & Script.Error.Line & ": " & vbCr _
& Script.Error.Text, vbCritical, "SYNTAX ERROR"
End If
End Sub
numa classe chamada matriz insira o codigo
Option Explicit
Property Get matriz(c_row As Integer, c_col As Integer) As Double
On Error Resume Next
matriz = Form2.grd.TextMatrix(c_row, c_col)
End Property
Property Let matriz(c_row As Integer, c_col As Integer, newValue As Double)
On Error Resume Next
matriz(c_row, c_col) = CStr(newValue)
End Property
Property Get formula(c_row As Integer, c_col As Integer) As String
On Error Resume Next
formula = Form2.grd.TextMatrix(c_row, c_col)
End Property
Property Let formula(c_row As Integer, c_col As Integer, newFormula As String)
On Error Resume Next
matriz(c_row, c_col) = newFormula
End Property
no form insira um msflexgrid no exemplo tem 15 linha 8 colunas cod do form
Private Sub grd_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then
grd.TextMatrix(row_atual, col_atual) = grd.TextMatrix(row_atual, col_atual) & Chr(KeyAscii)
GlobalMatriz.formula(row_atual, col_atual) = grd.TextMatrix(row_atual, col_atual)
Else
addCode row_atual, col_atual
End If
End Sub
Private Sub grd_SelChange()
col_atual = grd.Col
row_atual = grd.Row
End Sub
Private Sub Form_Load()
' create a reference to the Script Control
Set Script = CreateObject("ScriptControl")
End Sub