VBA migration to C# - V10 (Teclapressionada)

Asked

Viewed 284 times

-1

In VBA at the event Teclapressionada would be this way. Thanks to v/ help to convert to C#.

Private Sub EditorVendas_TeclaPressionada(KeyCode As Integer, Shift As Integer)
Dim i As Long
Dim CaractsArtigoPT As StdBECampos
Dim objLinha As GcpBELinhaDocumentoVenda

i = Me.DocumentoVenda.Linhas.NumItens

If KeyCode = KeyCodeConstants.vbKeyY And Shift = 2 Then

Set CaractsArtigoPT = BSO.Comercial.ArtigosIdiomas.DaValorAtributos(Me.DocumentoVenda.Linhas(i).Artigo, "PT", "Caracteristicas")

    If Not CaractsArtigoPT Is Nothing Then

        If CaractsArtigoPT.NumItens > 0 Then

            Set objLinha = New GcpBELinhaDocumentoVenda
                objLinha.TipoLinha = 60
                    objLinha.Descricao = "" & CaractsArtigoPT("Caracteristicas")
                        Me.DocumentoVenda.Linhas.Insere objLinha

        End If

    End If

Set CaractsArtigoPT = Nothing

End If

End Sub
  • Unless you want to take advantage of some specific functionality that only exists in C#, the easiest is to migrate from Vba to VB.net. Then it is easier to switch to C# because there are several online converters.

1 answer

1


The code will be something like this:

public override void TeclaPressionada(int KeyCode, int Shift, ExtensibilityEventArgs e)
{
    base.TeclaPressionada(KeyCode, Shift, e);

    int i = this.DocumentoVenda.Linhas.NumItens;
    StdBE100.StdBECampos CaractsArtigoPT = null;
    VndBE100.VndBELinhaDocumentoVenda objLinha = null;

    try
    {
        if (KeyCode == (int)Keys.Y && Shift == 2)
        {
            CaractsArtigoPT = BSO.Base.ArtigosIdiomas.DaValorAtributos(this.DocumentoVenda.Linhas.GetEdita(i).Artigo, "PT", "Caracteristicas");

            if (CaractsArtigoPT?.NumItens > 0)
            {
                this.DocumentoVenda.Linhas.Insere
                (
                    objLinha = new VndBE100.VndBELinhaDocumentoVenda()
                    {
                        TipoLinha = "60",
                        Descricao = PSO.Utils.FStr(CaractsArtigoPT["Caracteristicas"].Valor)
                    }
                );
            }

            CaractsArtigoPT = null;
        }
    }
    catch (System.Exception ex)
    {
        PSO.Dialogos.MostraErro(ex.Message, StdPlatBS100.StdBSTipos.IconId.PRI_Exclama);
    }
}

You still need to add references IBasBS100.dll and System.Windows.Forms.dll.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.