?
Solved

Convert list of bytes to byte array

Posted on 2010-01-09
5
Medium Priority
?
1,028 Views
Last Modified: 2013-11-08
I'm getting this error: Value of type 'System.Collections.Generic.List(Of Byte)' cannot be converted to '1-dimensional array of Byte'."

Form this code: (below)

I understand the error, I just don't know how to implement a fix.

Thanks!
Dim bt As String = contents

        Dim test As New List(Of Byte)()
        Dim pointer As Integer = 0
        While pointer < bt.Length
            Dim move As Integer = 3
            Dim temp1 As String = bt.Substring(pointer, 3)
            If Convert.ToInt32(temp1) > 255 Then
                temp1 = bt.Substring(pointer, 2)
                move = 2
            End If
            test.Add(Convert.ToByte(temp1))
            pointer += move + 1
        End While
        My.Computer.FileSystem.WriteAllBytes("C:\MyDocuments\CustomerData", test, True)

Open in new window

0
Comment
Question by:APag96
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26276478
Change:

    My.Computer.FileSystem.WriteAllBytes("C:\MyDocuments\CustomerData", test, True)

To:

    My.Computer.FileSystem.WriteAllBytes("C:\MyDocuments\CustomerData", test.ToArray, True)

The change was:

    test --> test.ToArray
0
 

Author Comment

by:APag96
ID: 26278483
I have tried that already and I get another error.  VB wants a byte array for the "WriteAllBytes"  code, but I created a list of bytes above.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 26278496
...and what error are you getting now?

"VB wants a byte array for the "WriteAllBytes"  code, but I created a list of bytes above."

Right...ToArray() creates a byte array from your List!
0
 

Author Comment

by:APag96
ID: 26278658
ok... ok... Let me try it again...
0
 

Author Closing Comment

by:APag96
ID: 31675135
It works. Thanks.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question