Object does not recognize member

Asked

Viewed 95 times

2

All I do is in Python. One of the functions I have to do is a conversion, where she tries to convert the value of TextBox and if it goes wrong, run the error block.

private void converter(object label)
{
    try
    {
        Convert.ToDouble(label.Text.Replace(".", ","));
    }
    catch
    {
        label.BackColor = Color.Red;
        LBL_ERR.Visible = true;
        LBL_ERR2.Visible = true;
        LBL_ERR2.Text = "VALORES INVÁLIDOS INSERIDOS";
        TXT_Altura.Text = "";
        TXT_Idade.Text = "";
        TXT_Peso.Text = "";
        LBL_IMCR.Text = "";
        LBL_TipoR.Text = "";
        LBL_SitR.Text = "";
        return;
    }

The error is in the function variables. I have tried using type variable string, int, object and nothing works, he accuses that the variable label has none of the required methods. Which type should I use to make it work?

Alleged error:

Gravidade Código  Descrição   Projeto Arquivo Linha   Estado de Supressão
Erro  CS1061  'object' não contém uma definição para 'BackColor' e não foi possível encontrar nenhum método de extensão 'BackColor'
acessível que aceite um primeiro argumento do tipo 'object' (há uma
diretiva de uso ou referência de assembly
ausente?) IMC C:\Users\LABINFO\source\repos\SLN_IMC\IMC\Form1.cs  30  Ativo
  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

2

The type to be received in the method (and not function) is Label and not object. That will solve this problem.

The code has other problems. You should not exchange a semicolon, you should use the culture system. You shouldn’t make an exception, you should make one TryParse(). And also, it is no mistake, but methods should have their names beginning in capital letters and preferably with a greater meaning than this, has face that it should not even exist, at least not in this way. And that seems like a monetary value, so it shouldn’t be like Double and yes Decimal. This is a Python error too.

Programming in one language is quite different from programming in another, contrary to what people imagine, it’s not because everyone has if that all are equal.

Browser other questions tagged

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