• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1174
  • Last Modified:

Define a Byte Array Structure

How can I define a byte structure on VB6?

on C this is what I would have done

char rawData[129] =
{
    0x7A, 0x00, 0x5E, 0xE8, 0x7A, 0x00, 0x01, 0x95, 0x01, 0x00, 0xF9, 0x0E, 0x00, 0x00, 0x0E, 0x00,
    0x55, 0x73, 0x65, 0x72, 0x31, 0x36, 0x33, 0x31, 0x32, 0x39, 0x34, 0x34, 0x31, 0x31, 0x01, 0x17,
    0x00, 0x57, 0x65, 0x6C, 0x63, 0x6F, 0x6D, 0x65, 0x20, 0x74, 0x6F, 0x20, 0x4D, 0x65, 0x72, 0x69,
    0x64, 0x69, 0x61, 0x6E, 0x20, 0x35, 0x39, 0x21, 0x02, 0x07, 0x00, 0x61, 0x64, 0x31, 0x2E, 0x61,
    0x76, 0x69, 0x12, 0x00, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x33,
    0x64, 0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x07, 0x00, 0x61, 0x64, 0x32, 0x2E, 0x61, 0x76, 0x69, 0x20,
    0x00, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6D, 0x65, 0x72, 0x69, 0x64, 0x69, 0x61, 0x6E,
    0x2E, 0x33, 0x64, 0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x6D, 0x65, 0x72, 0x69, 0x64, 0x69, 0x61,
    0x6E,
} ;

How can I achieve the above in VB6?
0
ITKnightMare
Asked:
ITKnightMare
1 Solution
 
junglerover77Commented:
Dim rawData(129) as Byte

rawData(0)=&H7A
rawData(1)=&H00
rawData(2)=&H5E
rawData(3)=&HE8
rawData(4)=&H7A
..................
0
 
EDDYKTCommented:
Or

Dim arr As Variant

arr = Array(CByte(&H7A), CByte(&H0), ...)
0
 
ronkleinCommented:
Note that junglerover77's solution depends on Option Base 0, which is the default (as much as I recall), but might be changed to 1.
Just to make sure, declare "Option Base 0" on the top of that module.
0
 
ArkCommented:
IMHO, thge best way is to use string:
Dim strRawData As String
strRawData = "z" & vbNullString & ^èz

To convert your array into string:
Private Sub Command1_Click()
   Debug.Print ArrayToString
End Sub

Private Function ArrayToString() As String
   Dim rawData As Variant
   rawData = Array(VBChar(&H7A), VBChar(&H0), VBChar(&H5E), VBChar(&HE8), VBChar(&H7A), VBChar(&H0), VBChar(&H1), VBChar(&H95), VBChar(&H1), VBChar(&H0), VBChar(&HF9), VBChar(&HE), VBChar(&H0), VBChar(&H0), VBChar(&HE), VBChar(&H0), _
             VBChar(&H55), VBChar(&H73), VBChar(&H65), VBChar(&H72), VBChar(&H31), VBChar(&H36), VBChar(&H33), VBChar(&H31), VBChar(&H32), VBChar(&H39), VBChar(&H34), VBChar(&H34), VBChar(&H31), VBChar(&H31), VBChar(&H1), VBChar(&H17), _
             VBChar(&H0), VBChar(&H57), VBChar(&H65), VBChar(&H6C), VBChar(&H63), VBChar(&H6F), VBChar(&H6D), VBChar(&H65), VBChar(&H20), VBChar(&H74), VBChar(&H6F), VBChar(&H20), VBChar(&H4D), VBChar(&H65), VBChar(&H72), VBChar(&H69), _
             VBChar(&H64), VBChar(&H69), VBChar(&H61), VBChar(&H6E), VBChar(&H20), VBChar(&H35), VBChar(&H39), VBChar(&H21), VBChar(&H2), VBChar(&H7), VBChar(&H0), VBChar(&H61), VBChar(&H64), VBChar(&H31), VBChar(&H2E), VBChar(&H61), _
             VBChar(&H76), VBChar(&H69), VBChar(&H12), VBChar(&H0), VBChar(&H68), VBChar(&H74), VBChar(&H74), VBChar(&H70), VBChar(&H3A), VBChar(&H2F), VBChar(&H2F), VBChar(&H77), VBChar(&H77), VBChar(&H77), VBChar(&H2E), VBChar(&H33), _
             VBChar(&H64), VBChar(&H6F), VBChar(&H2E), VBChar(&H63), VBChar(&H6F), VBChar(&H6D), VBChar(&H7), VBChar(&H0), VBChar(&H61), VBChar(&H64), VBChar(&H32), VBChar(&H2E), VBChar(&H61), VBChar(&H76), VBChar(&H69), VBChar(&H20), _
             VBChar(&H0), VBChar(&H68), VBChar(&H74), VBChar(&H74), VBChar(&H70), VBChar(&H3A), VBChar(&H2F), VBChar(&H2F), VBChar(&H6D), VBChar(&H65), VBChar(&H72), VBChar(&H69), VBChar(&H64), VBChar(&H69), VBChar(&H61), VBChar(&H6E), _
             VBChar(&H2E), VBChar(&H33), VBChar(&H64), VBChar(&H6F), VBChar(&H2E), VBChar(&H63), VBChar(&H6F), VBChar(&H6D), VBChar(&H2F), VBChar(&H6D), VBChar(&H65), VBChar(&H72), VBChar(&H69), VBChar(&H64), VBChar(&H69), VBChar(&H61), _
             VBChar(&H6E))
    ArrayToString = Join(rawData, "")
End Function

Private Function VBChar(ByVal bChar As Byte) As String
   VBChar = Chr(bChar)
End Function

Output in immediate window:
z ^èz • ù   User1631294411 Welcome to Meridian 59! ad1.avi http://www.3do.com ad2.avi  http://meridian.3do.com/meridian

'Note - vbNullString replaced with spaces in immediate window
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now