473,386 Members | 1,598 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,386 software developers and data experts.

newbee need help with code

Hi,

Can somebody translate the following c# code into Vb.Net?

byte[] myData = new byte[nFileLen];

I tried

Dim myData As Byte() = New Byte(nFileLen)

Does not compile , with error message:
Type 'byte' has no constructors.

TIA


Nov 21 '05 #1
10 4208
dim myData(nFileLen-1) as byte

"Danny Ni" <dn*@yahoo.com> escribió en el mensaje
news:uZ**************@tk2msftngp13.phx.gbl...
Hi,

Can somebody translate the following c# code into Vb.Net?

byte[] myData = new byte[nFileLen];

I tried

Dim myData As Byte() = New Byte(nFileLen)

Does not compile , with error message:
Type 'byte' has no constructors.

TIA

Nov 21 '05 #2
"Danny Ni" <dn*@yahoo.com> schrieb:
Can somebody translate the following c# code into Vb.Net?

byte[] myData = new byte[nFileLen];

I tried

Dim myData As Byte() = New Byte(nFileLen)

Does not compile , with error message:
Type 'byte' has no constructors.


I would choose the solution posted by alejandro. However, you can make the
code above work with a little change:

\\\
Dim FileLen As Integer = 22
Dim MyData1 As Byte() = New Byte(FileLen - 1) {}
Dim MyData3() As Byte = New Byte(FileLen - 1) {}
Dim MyData4(FileLen - 1) As Byte
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Dim myData(nFileLen) As Byte

"Herfried K. Wagner [MVP]" wrote:
"Danny Ni" <dn*@yahoo.com> schrieb:
Can somebody translate the following c# code into Vb.Net?

byte[] myData = new byte[nFileLen];

I tried

Dim myData As Byte() = New Byte(nFileLen)

Does not compile , with error message:
Type 'byte' has no constructors.


I would choose the solution posted by alejandro. However, you can make the
code above work with a little change:

\\\
Dim FileLen As Integer = 22
Dim MyData1 As Byte() = New Byte(FileLen - 1) {}
Dim MyData3() As Byte = New Byte(FileLen - 1) {}
Dim MyData4(FileLen - 1) As Byte
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
"Crouchie1998" <Cr**********@discussions.microsoft.com> schrieb:
Dim myData(nFileLen) As Byte


.... will create an array with 'nFileLen' + 1 elements with indices 0 through
'nFileLen'. I don't think that this is what the OP wants to archieve.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
I put the user's original C# code through two different convertors & they
both came up with the same result. One of these convertors is from the VB.NET
Resource Kit

"Herfried K. Wagner [MVP]" wrote:
"Crouchie1998" <Cr**********@discussions.microsoft.com> schrieb:
Dim myData(nFileLen) As Byte


.... will create an array with 'nFileLen' + 1 elements with indices 0 through
'nFileLen'. I don't think that this is what the OP wants to archieve.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"Crouchie1998" <Cr**********@discussions.microsoft.com> schrieb:
I put the user's original C# code through two different convertors & they
both came up with the same result. One of these convertors is from the
VB.NET
Resource Kit


So the converters are buggy. 'byte[] myData = new byte[nFileLen]' should
translate to 'Dim MyData(nFileLen - 1) As Byte'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Crouchie,

Because of probably compatible reasons does the array in VBNet create two
types arays in one.
One that fits the zero (C language compatible) indexer commands
One that fits the one (VB language compatible) indexer commands.

Therefore there is always created one item extra than you want. That is why
people like me (and probably Herfried) create arrays with indexes that are
forever -1 and start always with zero.

I don't (probably as you) understand why they did not build in with commands
as "mid" the method to subtract internal 1 from the indexer. However, they
did not and now because it is become standard for a long time not changable.

Probably one of those places where they did not wanted to change VB6 from
VBNet, although VB6 does not work with the framework and it could have been
only a framework part.

However the last parts are only my idea.

Cor
Nov 21 '05 #8
"Cor Ligthert" <no************@planet.nl> schrieb:
Because of probably compatible reasons does the array in VBNet create two
types arays in one.
One that fits the zero (C language compatible) indexer commands
One that fits the one (VB language compatible) indexer commands.

Therefore there is always created one item extra than you want. That is
why people like me (and probably Herfried) create arrays with indexes that
are forever -1 and start always with zero.


VB does /not/ support 1-based arrays. It only supports 0-based arrays, but
/collections/ are 1-based.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
Herfried,

They are zero based, however you can use them when you do it consequently as
1 base withouth any problem. (And than I mean real fixed arrays, when you
understand what I want to say with the last)

I never did that so you bring me in doubt.

Cor
Nov 21 '05 #10
"Cor Ligthert" <no************@planet.nl> schrieb:
They are zero based, however you can use them when you do it consequently
as 1 base withouth any problem. (And than I mean real fixed arrays, when
you understand what I want to say with the last)


You can use them, but there will always be one element in the array that is
not used, and the array's 'Length' property and 'GetLength'/'GetLowerBound'
will return "wrong" values.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #11

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

Similar topics

3
by: Newbee | last post by:
Hi ! Let's say that this is the folder on the server: /web/firstDir/secondDir/images/image.gif where i have stored my pictures. I have tryed with apsolute and relative paths but i can't display...
2
by: Newbee Adam | last post by:
some said that .NET app can run on any program where rutime exists. What is "runtime" in this sense? will I have to install runtime or .net framework or .NET support on an xp machine for a...
4
by: PerryC | last post by:
All, 1. Do the following codes seem ok? 2. If so, then how do I pull the value of YOE1 and YOE2 into my report? (to do some further calculations) ...
4
by: Martin Hvidberg | last post by:
Dear group I need to make a very simple piece of code in C, that can be command line executed and will compile on Linux, i.e. gcc. It should read a ascii Comma Separated Values (CSV) file and...
7
by: Greg P | last post by:
I'm new to VS2005 and want to simply update my data with the dataGridView that was generated when I draged my query from the Data Sources Pane. I think I may need to create a Data Adaptor but I'm...
8
by: ikarias | last post by:
Maybe not the right place to aske this, but a newbee (me) needs help. i trying to input a number into a textbox, so i can make a series of calculations. in the old days of basic i just jused...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
2
by: Mel | last post by:
I have a selection box with 3 values. what i need is to pass 3 urls to a function that has a switch statement and based on the selection index goes on one of the tree urls. Question is how do i...
0
by: Martin Arvidsson, Visual Systems AB | last post by:
Hi! I have a couple of newbee questions. I have a .aspx page with a couple of TextBoxes and a submit button. Now... When i press the submitbutton i want the data in the TextBoxes to be...
2
by: Rene | last post by:
Hello to all! I am a newbee to C++, I did a beginners' course, and now I am stuck with a strange problem. I have written the function that is pasted downwards. The peculiar thing is that when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...

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.