How to use an Array to sort out elements?

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 txtmessage.Text I'd like to put type 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 there are 9 TextBox that I want to be drawn to continue with the function.

Another thing, in SerialPort1 is it possible to insert an array list too? And if the SerialPort12 , say, it is unresponsive, can you give a Next to the next array list?

    
asked by anonymous 05.05.2017 / 02:49

2 answers

2

Hello I 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 have helped

    
05.05.2017 / 03:59
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
    
05.05.2017 / 03:51