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

VB usage of C# Dll Constructor and Enum

I know this is the VB languages new group. I have a .NET library (DLL)
written in C#. I am adding examples to my documentation for my VB users. I
have a VB example that will not compile.

C# struct and enum:

using System;

namespace VLib
{
public enum Types : sbyte
{
T1, T2, T3, T4,
}
public struct T
{
public ushort x;
public Types t;

public T( ushort x, Types t )
{
this.x = x;
this.t = t;
}
}
}

Compiles no errors.

Visual Basic Code:

Option Strict Off
Imports Vlib
Module Module1

Sub Main()

' The following errors occur on the definition below.

' Value of type 'Integer' cannot be converted to 'System.UInt16'.
' Value of type 'Byte' cannot be converted to 'VLib.Types'.
Dim q As VLib.T = New VLib.T(10, Types.T2)

End Sub

End Module

Ok What is going on here?

Do I need to cast the literal 10 to System.UInt16?
Why does VB think Types.T2 is of type BYTE and not of tyoe Types?

Nov 21 '05 #1
1 2797
In article <B5**********************************@microsoft.co m>, JimM wrote:
I know this is the VB languages new group. I have a .NET library (DLL)
written in C#. I am adding examples to my documentation for my VB users. I
have a VB example that will not compile.

C# struct and enum:

using System;

namespace VLib
{
public enum Types : sbyte
{
T1, T2, T3, T4,
}
public struct T
{
public ushort x;
public Types t;

public T( ushort x, Types t )
{
this.x = x;
this.t = t;
}
}
}

Compiles no errors.

Visual Basic Code:

Option Strict Off
Imports Vlib
Module Module1

Sub Main()

' The following errors occur on the definition below.

' Value of type 'Integer' cannot be converted to 'System.UInt16'.
' Value of type 'Byte' cannot be converted to 'VLib.Types'.
Dim q As VLib.T = New VLib.T(10, Types.T2)

End Sub

End Module

Ok What is going on here?

Do I need to cast the literal 10 to System.UInt16?
Why does VB think Types.T2 is of type BYTE and not of tyoe Types?


sbyte and UInt are not supported by vb.net. In other words, they
violate the CTS. Change the types in VLib to byte and short and you
shouldn't have any problems. If the value of T.x my exceed the limit of
a short, then you might want to promote it to an int.

--
Tom Shelton [MVP]
Nov 21 '05 #2

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

Similar topics

2
by: Eric C | last post by:
I'm reading a c++ book by Eric Nagler named Learning C++ and I ran into an exercise that requires a cpp file that defines several member functions of a header. Here is my problem, it defines a...
1
by: Eric C | last post by:
I'm reading a c++ book by Eric Nagler named Learning C++ and I ran into an exercise that requires a cpp file that defines several member functions of a header. Here is my problem, it defines a...
9
by: dumboo | last post by:
hi there, i was looking for some way to give default values to enum, when ever i m creating an enum variable it shuld be INITIALIZED to certain default values is it possible ? or do i have to...
2
by: lallous | last post by:
Hello I sometimes convert lots of numeric defines to enum, as: #define XYZ 0x12345 to enum some_consts {
6
by: randy1200 | last post by:
The following enum is given to me, and I can't change it: enum yo { ONE, TWO, THREE }; I have the following: char test = "ONE"; Any ideas on how to see if the string in "test" is in the...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
30
by: Philippe Bertrand | last post by:
Is this a bug in the C# compiler or CLR runtime? enum MyEnum { ZERO = 0, ONE = 1, TWO = 2 } class Foo { public Foo(string,object) { ... } public Foo(string,MyEnum) { ... } } Foo f = new...
4
by: =?Utf-8?B?0JrQvtC70LXQstCw?= | last post by:
I want to use an enum field in a constructor. For example: class Student { private string name; private enum university {.....}; private byte course; ......
0
by: tony_in_da_uk | last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and got a near-flippant response from someone who clearly didn't take the time to consider the import. I replied, and it's still not...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.