|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to split Hex String and fill byte buffer in VB 6.0Hi,
I am a beginner in VB6.0 I have a hex string like 01020304 I want to split the above sting with 2 chars and fill the byte buffer. For example Dim tempBuffer(3) as byte TempBuffer(0) = 04 TempBuffer(1) = 03 TempBuffer(2) = 02 TempBuffer(3) = 01 How can i do as stated above with VB6.0 string manipulation functions. Please help me.. Thanks Balaji Hi Balaji,
There's a couple of ways to do this. One way is to convert the value to a long then right shift the value and bitwise And the last byte, eg: Dim s As String Dim value As Long Dim i As Long Dim b(0 To 3) As Byte s = "&H01020304" value = CLng(s) For i = 3 To 0 Step -1 b(i) = value And &HFF value = value \ &H100 Next i Alternatively you could probably use string functions like Mid. Show quoteHide quote "IJALAB" <balaji.d***@gmail.com> wrote in message news:fd27efa4-5dec-4133-ad56-41f21b7d101e@l33g2000pri.googlegroups.com... > Hi, > > I am a beginner in VB6.0 > I have a hex string like 01020304 > I want to split the above sting with 2 chars and fill the byte buffer. > For example > > Dim tempBuffer(3) as byte > TempBuffer(0) = 04 > TempBuffer(1) = 03 > TempBuffer(2) = 02 > TempBuffer(3) = 01 > > How can i do as stated above with VB6.0 string manipulation functions. > Please help me.. > > Thanks > Balaji The easiest way is to use Mid$ to separate the elements and then CByte to
convert the string values into numerical values x = "01020304" TempBuffer(0) = CByte("&H" & Mid$(x,7,2)) TempBuffer(1) = CByte("&H" & Mid$(x,5,2)) TempBuffer(2) = CByte("&H" & Mid$(x,3,2)) TempBuffer(3) = CByte("&H" & Mid$(x,1,2)) The "&H" tells the system the numbers are in Hex. If all your numbers are below 10 you need not bother with the "&H" part. I leave it to you to work out how to make a loop so it'll cope with a string of any length Regards Dave O. Show quoteHide quote "IJALAB" <balaji.d***@gmail.com> wrote in message news:fd27efa4-5dec-4133-ad56-41f21b7d101e@l33g2000pri.googlegroups.com... > Hi, > > I am a beginner in VB6.0 > I have a hex string like 01020304 > I want to split the above sting with 2 chars and fill the byte buffer. > For example > > Dim tempBuffer(3) as byte > TempBuffer(0) = 04 > TempBuffer(1) = 03 > TempBuffer(2) = 02 > TempBuffer(3) = 01 > > How can i do as stated above with VB6.0 string manipulation functions. > Please help me.. > > Thanks > Balaji *** Sent via Developersdex http://www.developersdex.com ***
Hi Bill,
I am doing a similar type work I am receiiving a string from serial port which is also in hex format. I want to store it in a byte array using VB6.0 Please tell me howw to do that. Can I use similar function? Reply ASAP thanks in advance *** Sent via Developersdex http://www.developersdex.com *** Bhushan Deshpande wrote:
> I am doing a similar type work Bytes aren't formatted. They're just bytes.> I am receiiving a string from serial port which is also in hex format. > I want to store it in a byte array using VB6.0 Directly. Format them as hex if you want and as needed.> Please tell me howw to do that. If you're turning the bytes that come across the interface into a string that looks like hex, and would like to provide an example of such a string, many here could show you how to quickly break them down to their individual bytes.
Problem converting string to number: "Type mismatch" error
VB6: How to initialize a variable as a array structure / structure (type) array (see example) Screen resolution and Image Anchors and Objects Shelling to EXE not named EXE A query loosing its value? Commenting out a block of code with one click (OT) Anyone remember the formula? Runtime Error 91 Status Bar Question |
|||||||||||||||||||||||