tags:

views:

61

answers:

2

Hi guys, I am new to VB.net and struggling to get out of VB6's way of sending data, I am doing this to send a byte array from my client to server, please advice if this is the right way, thanks:

The sending portion:

 Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        Dim arrNo(3) As Integer
        arrNo(0) = 1400
        arrNo(1) = 1000
        arrNo(2) = 1200
        arrNo(3) = 1350

        Dim i As Integer
        For i = 0 To arrNo.Length - 1
            Dim outStream() As Byte = BitConverter.GetBytes(arrNo(i))
            Debug.Print(arrNo(i))
            serverStream.Write(outStream, 0, outStream.Length)
            serverStream.Flush()
        Next
    End Sub
+1  A: 

In VB6, an Integer was 2 bytes. Use Short in VB.NET. Move the Flush out of the For loop. The rest looks okay.

Hans Passant
A: 

In VB.NET you can declare the variable as part of the for loop syntax.

For i As Integer = 0 To arrNo.Length - 1
...
Next

You can also provide array initializers in the declaration (although that probably doesn't apply to your actual code so much as your sample code):

Dim arrNo As Integer() = {1400, 1000, 1200, 1350}
BlueMonkMN