USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Fórum

  Visual Basic
Voltar
Autor Assunto:  fórmulas num grid
ZeuzZ
QUEDAS DO IGUAÇU
PR - BRASIL
Postada em 26/01/2007 14:21 hs            
galera sera que tem como por exemplo, gravar num campo a formula do outro e executar num grid? tpw como se fosse um excell
?
 

-


Att


Lucas D. Alberti
lucas@visualsoftware.inf.br
www.visualsoftware.inf.br
     
Ama
Pontos: 2843
UBERLÂNDIA
MG - BRASIL
Postada em 26/05/2008 02:17 hs         
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
     
Página(s): 1/1    


Seu Nome:

Seu eMail:

ALTERAR PARA MODO HTML
Mensagem:

[:)] = 
[:P] = 
[:(] = 
[;)] = 

HTML DESLIGADO

     
 VOLTAR

  



CyberWEB Network Ltda.    © Copyright 2000-2025   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página