User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 422,962 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,940 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums

Coverting a string to a byte array

Join Date: Mar 2005
Posts: 32
Reputation: MrConfused is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
MrConfused MrConfused is offline Offline
Light Poster

Coverting a string to a byte array

  #1  
Apr 23rd, 2005
I have been given the following code to convert a string to a "byte array" (which is then passed to other software) but it does not appear to work. I have practically never needed to use a function and am even less familiar with the data type byte and Hex numbers. I think the Val("&H") + Mid$(QueryStr, ByteIndex * 2 + 1, 2) part is wrong (Very!). Any clues?

Type DATAQUERY
Data(SP_MAX_QUERY_SIZE - 1) As Byte
End Type

Global Const SP_MAX_QUERY_SIZE = 56

************************
The first QueryStr is "0C65450C"
I think QueryLength is 8.

************************

Public Function StringToDataQuery(QueryStr As String, QueryLength As Integer) As DATAQUERY

'This converts the query string to a query byte array
Dim ByteIndex As Integer
ByteIndex = 0
For ByteIndex = 0 To QueryLength - 1
StringToDataQuery.Data(ByteIndex) = _
Val("&H") + Mid$(QueryStr, ByteIndex * 2 + 1, 2)
Next ByteIndex

End Function
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 2:57 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC