473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Trouble defining a bytearray!!

Hello,
I am having trouble defining a byte array in .Net
When i go this route it doesnt like the [] definition
Dim xxxx[] As New Bytearray = {"0x45", "0x70", "0x22", "0x48", "0x9d",
"0x17", "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96",
"0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}

When I go this route

Dim xxx() As Byte = {"0x45", "0x70", "0x22", "0x48", "0x9d", "0x17", "0x22",
" 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96", "0x65", "0xc2",
"0x2d", "0x0c", "0x67", " 0xc7"}

It gives me a run-time error Input string was not in a correct format.

Running out of ideas..dont see any other definitons anywhere.

TIA,

HS


Nov 20 '05 #1
4 1347
"Harold S" <hs****@grange.com> schrieb
Hello,
I am having trouble defining a byte array in .Net
When i go this route it doesnt like the [] definition
Dim xxxx[] As New Bytearray = {"0x45", "0x70", "0x22", "0x48",
"0x9d", "0x17", "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f",
"0x5c", " 0x96", "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}

When I go this route

Dim xxx() As Byte = {"0x45", "0x70", "0x22", "0x48", "0x9d", "0x17",
"0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96",
"0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}

It gives me a run-time error Input string was not in a correct
format.


Run-time error? I can not even compile the code. Forgot to enable Option
Strict? Why assign strings to the array? Use numeric values:

Dim xxx() As Byte = {&H45, &h70,&H22, &H48}
--
Armin

Nov 20 '05 #2


Thanks Armin...I will give that a try!!
On an added note is there a site where i can find numeric equivalents
eg: for 0x300

Thanks a lot again!
Harry!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
"Harold Soans" <hs****@yahoo.com> schrieb


Thanks Armin...I will give that a try!!
On an added note is there a site where i can find numeric
equivalents eg: for 0x300


site? 3 * 256 = 768
You can use calc.exe.
or: msgbox(val("&H300"))
or: msgbox(convert.toint32("300",16))
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Harold S wrote:
Hello,
I am having trouble defining a byte array in .Net
When i go this route it doesnt like the [] definition
Dim xxxx[] As New Bytearray = {"0x45", "0x70", "0x22", "0x48", "0x9d",
"0x17", "0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", "
0x96", "0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}
[] is for C, C++, C#, and certain languages whose name starts with J.
When I go this route

Dim xxx() As Byte = {"0x45", "0x70", "0x22", "0x48", "0x9d", "0x17",
"0x22", " 0x11", " 0x7f", " 0x96", "0x5f", "0x8f", "0x5c", " 0x96",
"0x65", "0xc2", "0x2d", "0x0c", "0x67", " 0xc7"}


That's the correct way of doing it, only you are assigning Strings to a Byte
array. Naturally, it can't cast a String to a Byte. Assign it numbers
instead.
0x is the prefix for hex in C etc., in Visual Basic it's &H.
So your code would become:

Dim xxx() As Byte = {&H45, &H70, &H22, &H48, &H9D, &H17, _
&H22, &H11, &H7F, &H96, &H5F, &H8F, &H5C, &H96, _
&H65, &HC2, &H2D, &HC, &H67, &HC7}

--
Sven Groot
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kristina Engdahl | last post by:
Hello, I'm working with dynamic classloading and have encountered a problem when it comes to defining an URL for a file that is available through a bytearray representing a jar-file. The file in...
2
by: Lou | last post by:
How do I convert a byteArray to a string?
1
by: James Dean | last post by:
i cannot convert my arraylist of bytes to a byte array what could be the problem. i tried the following but it did not work: byte bytearray = (byte)tempbitarray.ToArray(tempbitarray.GetType()); ...
13
by: Ekim | last post by:
hy to all, I'm accessing a function from a managed-c++-dll within my c#-application. Therefore I encountered following troubles: In my c#-app I have got a byte-array, which should somehow be...
2
by: B-Dog | last post by:
I'm trying to download a csv file into a datatable but can't seem to figure it out. I can read the csv into a bytearray and view it but I'm having trouble trying to figure out get the downloaded...
1
by: gijamie911 | last post by:
int nBytes = 256; byte ByteArray = new byte; int nBytesRead = inputStream.Read(ByteArray, 0 , nBytes); recorderID = ""; for (int i...
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
8
by: Proaccesspro | last post by:
I'm trying to update a field in a table with the value of a text box in a report. Here is what I have: Private Sub Report_Close() Dim rs As Recordset Set rs = CurrentDb.OpenRecordset("OHPA...
3
by: EllieT | last post by:
Hi all, I've been fiddling around with creating a new database (Access 2003, Windows XP) for work the past two weeks and am having trouble defining my own customized (yet still automatic) primary...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.