0

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
2
  • What is the client-server communication mechanism you are using? Commented Jun 15, 2010 at 8:49
  • Hi, I am not too sure about your question but I am using System.Net.Sockets if that's what you are trying to ask. Thanks. Commented Jun 15, 2010 at 9:10

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.