|
-
Aug 23rd, 2004, 09:49 PM
#1
Thread Starter
Addicted Member
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.....
-
Aug 23rd, 2004, 09:56 PM
#2
Frenzied Member
Can you post the offensive code? I use GetBytes("some string") quite a bit with no troubles.
Mike
-
Aug 23rd, 2004, 10:11 PM
#3
Thread Starter
Addicted Member
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.
-
Aug 23rd, 2004, 10:27 PM
#4
Frenzied Member
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?
-
Aug 23rd, 2004, 10:29 PM
#5
Thread Starter
Addicted Member
Not quite sure.....
Can u prompt me what to do next...
Thanks..
-
Aug 24th, 2004, 09:06 AM
#6
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|