Results 1 to 6 of 6

Thread: Sending bytes

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    Sending bytes

    Hi

    Did anyone know how to use system.Text.Encoding.ASCII.GetBytes() to get multiples inputs from the textfield...

    Recently, i can only get one input from one textfield and send as one byte...how to receive from multiple textfields and send all as mukltiples bytes....

    Or is there another method better to use than this.....

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Can you post the offensive code? I use GetBytes("some string") quite a bit with no troubles.

    Mike

  3. #3

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Code:
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
    
            Dim networkStream As NetworkStream
    
            Try
                networkStream = tcpC.GetStream()
                If networkStream.CanWrite Then
                    Dim sendBytes As Byte()
                    sendBytes = System.Text.Encoding.ASCII.GetBytes(Info("", ""))
                    networkStream.Write(sendBytes, 0, sendBytes.Length)
                End If
    
            Catch ex As Exception
                Console.WriteLine("Sorry. This NetWorkStream is not use.")
            End Try
    
        End Sub
        Public Function Info(ByVal A As String, ByVal B As String) As String
            A = txtInfo.Text
            B = txtInfo2.Text
            Return (A) + (B)
        End Function
    
        Private Sub btnWriteTextbox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteTextbox.Click
    
            Dim networkStream As NetworkStream
            Dim write As StreamWriter
    
            Try
                networkStream = tcpC.GetStream()
                write = New StreamWriter("Hello.xml")
                Dim bytes(tcpC.ReceiveBufferSize) As Byte
                ' Sets the receive buffer size using the ReceiveBufferSize public property.
                tcpC.ReceiveBufferSize = 1024
    
                ' Gets the receive buffer size using the ReceiveBufferSize public property.
                If tcpC.ReceiveBufferSize = 1024 Then
                    networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
                    Dim data As String = System.Text.Encoding.ASCII.GetString(bytes)
                    txtInfo.Text = data
                    write.WriteLine(txtInfo.Text)
                    write.Close()
                End If
    
            Catch ex As Exception
                Console.WriteLine("Sorry. This NetWorkStream is not use.")
            End Try
    
        End Sub
    Last edited by toytoy; Dec 3rd, 2004 at 08:18 AM.

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Question Expression within assignment?

    Allright. Is A + B returning what you expect? I'm guessing that's where the problem is. Also, do you know how to format your code using the vb tags?

  5. #5

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Not quite sure.....

    Can u prompt me what to do next...

    Thanks..

  6. #6
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I'd probably just do a little debugging. Set a break point, or just step through your code. I guess this is happening in your btnSend_Click method? Make sure your Info method is returning what you expect.

    And if you use [ vbcode ] and [ /vbcode ] (without the spaces) around the code you post, it makes it much easier to read.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width