Marc Noguera
Marc Noguera

Reputation: 13

int to textbox.text with C#

With VB I have no error with this method

Private Sub But_Leer_Click(sender As Object, e As EventArgs) Handles But_Leer.Click

    Dim INT(3) As Integer
    ProEasy.ReadDevice32("LT4000_1.#INTERNAL", "Valor1", INT, 1)
    TextBox1.Text = INT(0)

But with C#, I have an error when assigning "Valor" int to Textbox1.text. A string is required:

private void button2_Click(object sender, EventArgs e)
    {
        int[] Valor = new int[3];
        ProEasy.ReadDevice32("LT4000_1.PLC1", "MWO", out Valor, 1);
        textBox1.Text = **Valor**[0];

Anyone knows why? I just starting with VB and C# language

Upvotes: 1

Views: 207

Answers (2)

Roman Marusyk
Roman Marusyk

Reputation: 24619

Valor[0] returns int, you need to convert it to string

textBox1.Text = Valor[0].ToString();

Upvotes: 1

oopbase
oopbase

Reputation: 11415

The Text property of the TextBox control requires a string. Valor is an array containing integer values. Therefore you will have to cast that value to string.

textBox1.Text = Valor[0].ToString();

Upvotes: 1

Related Questions