Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Convert list of bytes to byte array

Posted on 2010-01-09
5
Medium Priority
?
1,120 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
  • 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

578 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