Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BitConverter with CType 1

Status
Not open for further replies.

jasc2k

Programmer
Nov 2, 2005
113
GB
Hi all,

I will try to keep this as simple as possible as the project is quite large.
But quite simply we have a signature capture app that capture the coordinates of lines of a signature that posts them into an SQL column as 'image'.
We then convert the contents using:
Code:
recSign = BitConverter.ToString(CType(res.item("recSign"), Byte())
so the data is now in string format so that we can send using TCP sockets.

My problem lies quite simply when trying to convert back from a string into the correct format as if it just came from SQL 'image' format. Really I dont even know what the format should be let alone start working out code :)

I have tried many examples from online but Im just not getting the right format, maybe its as simple as the opposite of the above code for someone?

Any ideas?
Many thanks,
James

- free mp3 downloads and streaming
 
How are you reading in the data being sent? Is your program doing it directly or is it saved some where frist?

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
hi there,
thanks for your reply :)

its my program directly receiving data from a TCP socket, however I was testing it by declaring a string that I knew would be correct.
One thing I thought of recently that I have not tested is instead of declaring a string declaring it as an object then changing the type to a byte array?

I will post some of my test code tomorrow to show an example of my non progress :)

Thanks

- free mp3 downloads and streaming
 
Look into the BinaryFormatter class.

The difficulty is with the BinaryFormatter the serialize method takes a Stream that it puts all the serialized data in. To get that into a Byte array, you need to do the following.

Code:
Dim ret() As Byte = Nothing
Dim ms As New MemoryStream()
Dim bf As New BinaryFormatter()
Try
    bf.Serialize(ms, obj)
Finally
    ms.Close()
End Try
ret = ms.ToArray()

See the Deserialize method for converting back to the original.
 
hi there,
many thanks for your post it has proved very interesting - I had not seen any posts relative to this binary formatter.

I have now fixed my issue or should I say worked around my issue as it turns out what I was trying to do was not exactly what I wanted anyway.

hrmm hindsight lol.

Thanks

- free mp3 downloads and streaming
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top