473,387 Members | 1,578 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.

From C# to VB.NET

Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}

What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer

May 14 '07 #1
15 1206
On May 14, 10:20 am, Robert Scheer <rbsch...@my-deja.comwrote:
Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}

What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer
Off the top of my head:

Public Overrides Function Check(member as Member) As ProblemCollection
Dim method As Method = CType(member, Method)
End Function

Thanks,

Seth Rowe

May 14 '07 #2
VB.net is not case sensitive.

so in C#
Employee employee = new Employee();

will work

in VB.net

dim employee as Employee = new Employee()

will NOT work
you gotta go with

dim emp as Employee = new Employee

(or similar)

watch those properties too for case sensitivity.


"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
On May 14, 10:20 am, Robert Scheer <rbsch...@my-deja.comwrote:
Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}

What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer

Off the top of my head:

Public Overrides Function Check(member as Member) As ProblemCollection
Dim method As Method = CType(member, Method)
End Function

Thanks,

Seth Rowe

May 14 '07 #3
The equivalent is not a simple 'CType'.
(via Instant VB)
VB 2005:
Dim method As Method = TryCast(member, Method)
VB 2003:
Dim method As Method = CType(IIf(TypeOf member Is Method, member, Nothing),
Method)

As 'sloan' mentioned you'll also have to rename 'method' since VB is not
case sensitive.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Robert Scheer" wrote:
Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}

What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer

May 14 '07 #4
dim emp as Employee = new Employee
>
(or similar)

watch those properties too for case sensitivity.
Actually vb lets you get away with a variable the same name as a Type.
It just won't let you have two variables of the same (case
insensitive) name like in C#

i.e.

This compiles fine:

Dim employee As New Employee()
employee.Name = "Seth Rowe"
Console.WriteLine(employee.Name)

And even this will work:

Dim Employee As New Employee()
Employee.Name = "Seth Rowe"
Console.WriteLine(Employee.Name)

However in C# you can do this:

Employee Employee = new Employee();
Employee employee = new Employee();
Employee.Name = "Employee 1";
employee.Name = "employee 2";
Console.WriteLine(Employee.Name);
Console.WriteLine(employee.Name);

But the VB version will fail due to case insensitivity:

Dim Employee As New Employee()
Dim employee As New Employee()
Employee.Name = "Employee 1"
employee.Name = "employee 2"
Console.WriteLine(Employee.Name)
Console.WriteLine(employee.Name)

However, for sake of readability, I would follow you suggestion of
using a shortened version of the type name for the variable.

Thanks,

Seth Rowe
On May 14, 10:38 am, "sloan" <s...@ipass.netwrote:
VB.net is not case sensitive.

so in C#

Employee employee = new Employee();

will work

in VB.net

dim employee as Employee = new Employee()

will NOT work
you gotta go with

dim emp as Employee = new Employee

(or similar)

watch those properties too for case sensitivity.

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11**********************@e65g2000hsc.googlegr oups.com...
On May 14, 10:20 am, Robert Scheer <rbsch...@my-deja.comwrote:
Hi.
I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:
public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}
What kind of construct is this? Is there an equivalent construct in
VB.NET?
Regards,
Robert Scheer
Off the top of my head:
Public Overrides Function Check(member as Member) As ProblemCollection
Dim method As Method = CType(member, Method)
End Function
Thanks,
Seth Rowe

May 14 '07 #5
"sloan" <sl***@ipass.netwrote in news:#3XtIWjlHHA.4032
@TK2MSFTNGP02.phx.gbl:
dim employee as Employee = new Employee()

will NOT work
you gotta go with
Actually that does work...
May 14 '07 #6
The equivalent is not a simple 'CType'.

Thanks David, I forgot "as Type" returned null if the cast failed.
Fortunately I tagged my post with "Off the top of my head"

:-)

Thanks,

Seth Rowe
On May 14, 10:48 am, David Anton
<DavidAn...@discussions.microsoft.comwrote:
The equivalent is not a simple 'CType'.
(via Instant VB)
VB 2005:
Dim method As Method = TryCast(member, Method)
VB 2003:
Dim method As Method = CType(IIf(TypeOf member Is Method, member, Nothing),
Method)

As 'sloan' mentioned you'll also have to rename 'method' since VB is not
case sensitive.
--
David Antonwww.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI

"Robert Scheer" wrote:
Hi.
I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:
public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}
What kind of construct is this? Is there an equivalent construct in
VB.NET?
Regards,
Robert Scheer

May 14 '07 #7

Hmmm.

You're right, I guess I assumed it would fail, and never tested it.

But ... (as mentioned) readability and prone to bugs is still an issue.

THanks for the correction.


"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"sloan" <sl***@ipass.netwrote in news:#3XtIWjlHHA.4032
@TK2MSFTNGP02.phx.gbl:
dim employee as Employee = new Employee()

will NOT work
you gotta go with

Actually that does work...

May 14 '07 #8


"Robert Scheer" <rb******@my-deja.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}

What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer
Either use the inline-if method post from David Anton or:

Public Overrides Function Check(member As Member) As ProblemCollection
Dim method As Method = Nothing
If TypeOf method Is Method
method = CType(method, Method)
End If
...
End Function

AFAIK, using the IIF statement will cause extra (albeit, very small amount
of) overhead because IIF is actually a function itself...remember though,
it's probably negligible for your application...

HTH,
Mythran
May 14 '07 #9
Turn Option Strict On. Then the compiler will warn you when you give a
variable the same name as a type.

Mike.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"sloan" <sl***@ipass.netwrote in news:#3XtIWjlHHA.4032
@TK2MSFTNGP02.phx.gbl:
>dim employee as Employee = new Employee()

will NOT work
you gotta go with

Actually that does work...

May 14 '07 #10
On May 14, 11:25 am, "Michael D. Ober" <obermd.@.alum.mit.edu.nospam>
wrote:
Turn Option Strict On. Then the compiler will warn you when you give a
variable the same name as a type.

Mike.

"Spam Catcher" <spamhoney...@rogers.comwrote in message

news:Xn**********************************@127.0.0. 1...
"sloan" <s...@ipass.netwrote in news:#3XtIWjlHHA.4032
@TK2MSFTNGP02.phx.gbl:
dim employee as Employee = new Employee()
will NOT work
you gotta go with
Actually that does work...
Turn Option Strict On. Then the compiler will warn you when you give a
variable the same name as a type.
It does? None of the examples I posted earlier caused a warning to
show. Do you have an example demonstrating this?

Thanks,

Seth Rowe

May 14 '07 #11

Aha!

I default to that, including setting it in the project properties.

And I set it to "Raise Exception".

Sorry, I only occasionally code vb.net.

Thanks Michael for solving the (small) mystery.


"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:eK*************@TK2MSFTNGP06.phx.gbl...
Turn Option Strict On. Then the compiler will warn you when you give a
variable the same name as a type.

Mike.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"sloan" <sl***@ipass.netwrote in news:#3XtIWjlHHA.4032
@TK2MSFTNGP02.phx.gbl:
dim employee as Employee = new Employee()

will NOT work
you gotta go with
Actually that does work...


May 14 '07 #12

"Robert Scheer" <rb******@my-deja.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}

What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer
I use a C# to VB converter named Instant VB from
http://www.tangiblesoftwaresolutions.com/

You can get a trial copy. I put your code snippet in and got the answer that
several people have given you.

Galen
May 14 '07 #13
"Robert Scheer" <rb******@my-deja.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
>Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}
What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer
I use a C# to VB converter named Instant VB from
http://www.tangiblesoftwaresolutions.com/

You can get a trial copy. I put your code snippet in and got the
answer that several people have given you.

Galen
here are a few free convertors

http://www.econdimension.ch/en/sol_netvert.html

http://converter.telerik.com/
May 15 '07 #14
Did you try the OP's code on these free converters? (you might want to do
that)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"Jay Parzych" wrote:
"Robert Scheer" <rb******@my-deja.comwrote in message
news:11**********************@n59g2000hsh.googlegr oups.com...
Hi.

I am trying to port a library from C# to VB.NET. I have 95% of this
code already ported, but I do not know how to translate the line
below:

public override ProblemCollection Check(Member member)
{
Method method = member as Method;
....
}
What kind of construct is this? Is there an equivalent construct in
VB.NET?

Regards,
Robert Scheer
I use a C# to VB converter named Instant VB from
http://www.tangiblesoftwaresolutions.com/

You can get a trial copy. I put your code snippet in and got the
answer that several people have given you.

Galen

here are a few free convertors

http://www.econdimension.ch/en/sol_netvert.html

http://converter.telerik.com/
May 15 '07 #15
On May 14, 11:45 am, rowe_newsgroups <rowe_em...@yahoo.comwrote:
On May 14, 11:25 am, "Michael D. Ober" <obermd.@.alum.mit.edu.nospam>
wrote:
Turn Option Strict On. Then the compiler will warn you when you give a
variable the same name as a type.
Mike.
"Spam Catcher" <spamhoney...@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"sloan" <s...@ipass.netwrote in news:#3XtIWjlHHA.4032
@TK2MSFTNGP02.phx.gbl:
>dim employee as Employee = new Employee()
>will NOT work
>you gotta go with
Actually that does work...
Turn Option Strict On. Then the compiler will warn you when you give a
variable the same name as a type.

It does? None of the examples I posted earlier caused a warning to
show. Do you have an example demonstrating this?

Thanks,

Seth Rowe
Sorry for reviving this thread - but I still can't get a warning from
the compiler for naming a variable the same name as a Type, even with
Option Strict On. Is there an option I'm missing somewhere?

Thanks,

Seth Rowe

May 15 '07 #16

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

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
16
by: Fuzzyman | last post by:
Hello, To create a classic (old style) class, I write : class foo: pass To do the equivalent as a new style class, I write : class foo(object):
2
by: nitin | last post by:
g++ -c $INCLUDES ActualPEResult.cpp In file included from /usr/include/c++/3.2.2/backward/iostream.h:31, from /home/pradeepks/Linux_Porting/dcpfrontier/dcpdev/dcp_components/trap...
4
by: susmita_ganguly | last post by:
Hi I am trying to upgrade from oracle 8i to oracle 9i on the same server ..I don't know much abt migration . Can anyone help me out. Thanks. Susmita
2
by: cs168 | last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: RSH | last post by:
Im trying to create a stored procedure of the following code. I want to set it so that I have to send the first 4 variables (@DB, @BackUpFile,@TestDB,@RestoreFile). I am having trouble when i try...
20
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.