Convert 1 line of C# to VB.Net

S

Stephen Miller

Hi,

I am converting a code sample found at
http://support.microsoft.com/default.aspx?scid=kb;en-us;828279 from C#
to VB and I am stuck on one line of code. How would I convert:

object[] pos = new object[numaxes];

(where numaxes is an int) to VB.Net?

I have tried

Dim pos() As Object = New Object(numaxes)
,
Dim pos(numaxes) As Object = New Object

and

Dim pos As Object() = New Object
ReDim pos(numaxes)

but these attempts all generate errors

Thanks,

Stephen
 
T

Tom Shelton

Hi,

I am converting a code sample found at
http://support.microsoft.com/default.aspx?scid=kb;en-us;828279 from C#
to VB and I am stuck on one line of code. How would I convert:

object[] pos = new object[numaxes];

(where numaxes is an int) to VB.Net?

I have tried

Dim pos() As Object = New Object(numaxes)
,
Dim pos(numaxes) As Object = New Object

and

Dim pos As Object() = New Object
ReDim pos(numaxes)

but these attempts all generate errors

Thanks,

Stephen

Dim pos(numaxes) As Object

You should be aware that the array bounds semantics are different in VB.NET
then C#. Say numaxes = 5. In C#, the statement Object[] pos = new
Object[numaxes] would create a 5 element array with indexes 0 to 4. The
above VB.NET statement, will create a 6 element array with indexes 0 to 5.
Just another little gotcha when converting C# to VB.NET :)

HTH
 
G

Guest

Hi Stephen Miller

Try this following code, this will work

Dim pos(numaxes) As Object

Array declarations in VB.NET is like this only. That syntax holds good only for C#

Sadha Sivam
Microsoft Community Star
Malleable Minds Software Pvt Ltd.
India.
 
S

scamp

From what I can see this is an Int16 type array declaration - so all
you need to do is declare an Array of type int - size numaxes. Do not
know much about c# though so could be wrong!!

Maybe try something like:

Dim pos(numaxes) As int16
 
C

Cor Ligthert

Hi Herfried,

Tom wrote this already, however when this was really needed I would choise
in this case for
\\\
Dim pos() As Object = New Object(numaxes - 1) {}
///
Dim pos(numaxes - 1) As Object

I think that this looks more to VB.net than that C# code you provided.

It seems that you like the C# context more however I see no reason to show
that in a language.vb newsgroup.

Just my thought,

:))))))

Cor
 
H

Herfried K. Wagner [MVP]

Hi Cor,

* "Cor Ligthert said:
Tom wrote this already, however when this was really needed I would choise
in this case for
Dim pos(numaxes - 1) As Object

I think that this looks more to VB.net than that C# code you provided.

It seems that you like the C# context more however I see no reason to show
that in a language.vb newsgroup.

It's still valid VB.NET syntax, and has nothing to do with C# syntax.
It's simply an alternative ;-))).
 
S

Stephen Miller

Both of these methods work, however I have hit another snag converting
a subsequent line of code that uses the pos() object array. The C#
code uses the ref method parameter keyword:

ADOMD.Cell cell = oAdoMDCellSet.get_Item(ref pos);

What is the VB.Net equivilant to 'ref pos'?

I figured it may look like:

Dim cell As ADOMD.Cell = oAdoMDCellSet.get_Item(byref pos)

... but this generates errors

Thanks, for your suggestions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top