How to use an Array to draw elements?

Asked

Viewed 72 times

1

I have this code

 With SerialPort1
            .Write("AT" & vbCrLf)
            Threading.Thread.Sleep(1000)
            .Write("AT+CMGF=1" & vbCrLf)
            Threading.Thread.Sleep(1000)
            .Write("AT+CMGS=" & Chr(34) & txtnumber.Text & Chr(34) & vbCrLf)
            .Write(txtmessage.Text & Chr(26))
            Threading.Thread.Sleep(1000)
        End With

let’s say in the txtmessage.Text I want to put like mensagem[i].Text with an array list.

Example:

    Private Sub menssagem(txtmessage, TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8)
    Dim menssagem(8) As Integer

End Sub

in total are 9 TextBox that I want to be drawn to continue with the function.

Another thing, in the SerialPort1 Is it possible for me to enter an array list as well? What if the SerialPort12, let’s say, she’s unanswered, has a way Next to the next array list?

2 answers

2

If I understand, you just have to use Rnd():

    With SerialPort1
        .Write("AT" & vbCrLf)
        Threading.Thread.Sleep(1000)
        .Write("AT+CMGF=1" & vbCrLf)
        Threading.Thread.Sleep(1000)
        .Write("AT+CMGS=" & Chr(34) & txtnumber.Text & Chr(34) & vbCrLf)
        .Write(mensagem[CInt(Math.Ceiling(Rnd() * 9))].Text & Chr(26))
        Threading.Thread.Sleep(1000)
    End With

2

Hello made an example in C#, you can adapt it to VB:

TextBox[] array = new TextBox[10];
array[0] = textBox1;
array[1] = textBox2;
array[2] = textBox3;
array[3] = textBox4;
array[4] = textBox5;
array[5] = textBox6;
array[6] = textBox7;
array[7] = textBox8;
array[8] = textBox9;
array[9] = textBox10;
Random r = new Random();
for (int i = 0; i < array.Length; i++)
{
     Thread.Sleep(200);
     var index = r.Next(array.Length);
     array[index].Text = $"Indice sortiado {index}, nome do textbox  {array[index].Name}";
}

I hope I’ve helped

  • I can do the same thing with the SerialPort1 ? I’m 12 [Serialport]

  • Yes, the algorithm is the same.

  • Just to wrap up, if I put this Vb.net code inside a Private Sub, then I just write it in the function ? .Write(array[index].Text & Chr(26))

  • @Mandrakevenom yes you can do just that

Browser other questions tagged

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