Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 15th, 2006, 05:23 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Converting a String to a Byte array

This flew fine in VB6:
Code:
    Dim Text As String
    Dim abytText() As Byte

    Text = "Some Text"
    abytText = InText   ' abytText is now an array of bytes holding the text.
But in VB.NET ’05, using
Code:
    Dim data As String = "Some Stuff"
    Dim aByteText() As Byte = data
    causes a blue warning squiggle under the reference to the variable data. When I hover over it, the tip says, "Value of type 'String' cannot be converted to '1-dimensional array of Byte'."

I believe that if I used a conversion function to type Byte, it would argue because a string can't be recognized as a single-byte value. As they used to say in commercials for Jiff (gender notwithstanding), “What’s a mother to do?”
  #2 (permalink)  
Old December 15th, 2006, 05:50 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Indeed:
Code:
    Dim aByteText() As Byte = CType(data.ToCharArray, Byte)
                                    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
                                    "Value of type '1-dimensional array of char' cannot be converted to 'Byte'."
  #3 (permalink)  
Old February 20th, 2007, 11:03 PM
Authorized User
 
Join Date: Dec 2006
Location: Fort Collins, Colorado, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to maxl
Default

You could use:

Imports system.text

Dim aByteText() as Byte = Encoding.UTF8.GetBytes(data)

Or UTF7, UTF32, Unicode...its all under the Encoding class.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing byte array into image file yukijocelyn C# 2005 1 August 6th, 2008 03:45 PM
Converting int to byte yukijocelyn C# 2005 1 May 30th, 2008 03:44 AM
display byte array of pdf in jsp mahendra.w JSP Basics 2 September 23rd, 2007 11:23 PM
display byte array of jpeg in jsp mahendra.w JSP Basics 1 September 4th, 2007 06:53 AM
converting image in picturebox to byte[] connect2sandep General .NET 0 July 26th, 2005 04:31 PM



All times are GMT -4. The time now is 06:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.