Help needed for VB --> C# translation

T

tiger79

Hi,
I've been translating some API's from VB to C# for a couple of days now.
Only I'm a real newbie to both languages, but I managed to do most of it
except the next statements, so if anyone knows what the counterpart in C# is
of those VB statements I would appreciate :

Public Function (ok, public I know but what is a Function in C# ?)

Public Enum

Friend Property (need to know both Friend and Property)

Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)

On Error GoTo errHandler

Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)

Exit Function

Set NewEnum = mCol.[_NewEnum]

And is there in C# something like modules (classes) ???

Thanx, please respond if u knw any of these...
 
M

Morten Wennevik

Hi,
I've been translating some API's from VB to C# for a couple of days now.
Only I'm a real newbie to both languages, but I managed to do most of it
except the next statements, so if anyone knows what the counterpart in C# is
of those VB statements I would appreciate :

Public Function (ok, public I know but what is a Function in C# ?)

Sub and Function is the same in C#. A Sub is a method returning 'void', where a Function can return anything else.

public void DoSomething() // Public Sub DoSomething
{
}

public string DoSomething() // Public Function DoSomething
{
}

Public Enum

public enum
Friend Property (need to know both Friend and Property)

Someone else could explain this much better than me. I don't think there is a Friend in C#
Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)

DAO.Recordset wRecordset;
DAO is a namespace or class where Recordset is defined
On Error GoTo errHandler

try
{
}
catch
{
}

Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)

Not sure if there is a C# counterpart of Collection
Exit Function

return;

Set NewEnum = mCol.[_NewEnum]

Not sure
And is there in C# something like modules (classes) ???

There is a Module class if that is what you mean. It's in .Net Framework and doesn't belong to any particular language.
 
J

John Wood

Public Function (ok, public I know but what is a Function in C# ?)

public int myFunction()
{

}

(where int is the return type, myFunction is the function name)
Public Enum
pretty much the same.
public enum myEnum
{
element1,
element2
}
Friend Property (need to know both Friend and Property)
internal int myProperty
{
get
{
return someValue;
}
set
{
someVariable = value;
}
}
Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)
No such thing. DataTable is probably the closest thing, you'll have to read
up on it I'm afraid as they're quite different.
Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)
Hashtable mCol = new Hashtable();

Don't forget to put a 'using System.Collections' at the top.
Exit Function return

Set NewEnum = mCol.[_NewEnum]
IEnumerator newEnum = mCol.GetEnumerator()
And is there in C# something like modules (classes) ???
public class MyClass
{

}
 
T

tiger79

First of all thanx for the swift answers,
I'd like to point out something regarding this :
Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)
No such thing. DataTable is probably the closest thing, you'll have to read
up on it I'm afraid as they're quite different.

I am using a SQL CE 2.0 database now instead than a reald dataset, so is
there code that directly connects to such databases ???


John Wood said:
Public Function (ok, public I know but what is a Function in C# ?)

public int myFunction()
{

}

(where int is the return type, myFunction is the function name)
Public Enum
pretty much the same.
public enum myEnum
{
element1,
element2
}
Friend Property (need to know both Friend and Property)
internal int myProperty
{
get
{
return someValue;
}
set
{
someVariable = value;
}
}
Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)
No such thing. DataTable is probably the closest thing, you'll have to read
up on it I'm afraid as they're quite different.
Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)
Hashtable mCol = new Hashtable();

Don't forget to put a 'using System.Collections' at the top.
Exit Function return

Set NewEnum = mCol.[_NewEnum]
IEnumerator newEnum = mCol.GetEnumerator()
And is there in C# something like modules (classes) ???
public class MyClass
{

}
 
P

Peter van der Goes

tiger79 said:
Hi,
I've been translating some API's from VB to C# for a couple of days now.
Only I'm a real newbie to both languages, but I managed to do most of it
except the next statements, so if anyone knows what the counterpart in C# is
of those VB statements I would appreciate :

Public Function (ok, public I know but what is a Function in C# ?)

Public Enum

Friend Property (need to know both Friend and Property)

Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)

On Error GoTo errHandler

Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)

Exit Function

Set NewEnum = mCol.[_NewEnum]

And is there in C# something like modules (classes) ???

Thanx, please respond if u knw any of these...
I don't want to pour cold water on your aspirations, but just telling you
(roughly) equivalent keywords isn't going to help you much, unless you know
something about the .NET Framework and the differences between .NET
languages and pre-.NET Visual Basic.

I could tell you that the equivalent of Function Procedure (or Subprocedure,
for that matter) is either value returning method or void method, but that's
not much help if you don't know that the word method does not appear in a C#
method definition or call.

Another example: On Error GoTo ~== try, catch, finally, but the translation
requires that you understand a completely new and different error handling
mechanism.

I believe you need some basic training in both .NET and C# to be successful.
There are lots of places on the web where you can start:

http://www.csharp-station.com/
http://support.microsoft.com/default.aspx?pr=vcc
http://support.microsoft.com/default.aspx?scid=fh;EN-US;vbdnmig&product=vbNET
http://support.microsoft.com/default.aspx?scid=kb;en-us;309617
 
T

tiger79

Thanx, but maybe I've exageratted by saying im a real newbie... I've been
using C# for 2 months now to develop Compact Framework softwar (on a
pocketpc)...
Before that I've been using C++ and Java, so about methods and stuff I know
the basics...
And when I rougly know what the translation is it goes unsaid that first I
try to get out of MSDN as much as I can about the new statements or
argument....


Peter van der Goes said:
tiger79 said:
Hi,
I've been translating some API's from VB to C# for a couple of days now.
Only I'm a real newbie to both languages, but I managed to do most of it
except the next statements, so if anyone knows what the counterpart in
C#
is
of those VB statements I would appreciate :

Public Function (ok, public I know but what is a Function in C# ?)

Public Enum

Friend Property (need to know both Friend and Property)

Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)

On Error GoTo errHandler

Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)

Exit Function

Set NewEnum = mCol.[_NewEnum]

And is there in C# something like modules (classes) ???

Thanx, please respond if u knw any of these...
I don't want to pour cold water on your aspirations, but just telling you
(roughly) equivalent keywords isn't going to help you much, unless you know
something about the .NET Framework and the differences between .NET
languages and pre-.NET Visual Basic.

I could tell you that the equivalent of Function Procedure (or Subprocedure,
for that matter) is either value returning method or void method, but that's
not much help if you don't know that the word method does not appear in a C#
method definition or call.

Another example: On Error GoTo ~== try, catch, finally, but the translation
requires that you understand a completely new and different error handling
mechanism.

I believe you need some basic training in both .NET and C# to be successful.
There are lots of places on the web where you can start:

http://www.csharp-station.com/
http://support.microsoft.com/default.aspx?pr=vcc
http://support.microsoft.com/default.aspx?scid=fh;EN-US;vbdnmig&product=vbNET
http://support.microsoft.com/default.aspx?scid=kb;en-us;309617
 
J

John Wood

Hmmm... sorry I don't know that much about SQL for CE. But all .net
implementations, on pocketpc or whatever, use ADO.Net. Have a look at the
SqlClient namespace for more info on how you can use DataTables with SQL.

tiger79 said:
First of all thanx for the swift answers,
I'd like to point out something regarding this :
Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset part)
No such thing. DataTable is probably the closest thing, you'll have to read
up on it I'm afraid as they're quite different.

I am using a SQL CE 2.0 database now instead than a reald dataset, so is
there code that directly connects to such databases ???


John Wood said:
Public Function (ok, public I know but what is a Function in C# ?)

public int myFunction()
{

}

(where int is the return type, myFunction is the function name)
Public Enum
pretty much the same.
public enum myEnum
{
element1,
element2
}
Friend Property (need to know both Friend and Property)
internal int myProperty
{
get
{
return someValue;
}
set
{
someVariable = value;
}
}
Dim wRecordset As DAO.Recordset (I need to know the DAO.Recordset
part)
No such thing. DataTable is probably the closest thing, you'll have to read
up on it I'm afraid as they're quite different.
Private mCol as Collection (C# counterpart of Collection ??, thought i could
use object here)
Hashtable mCol = new Hashtable();

Don't forget to put a 'using System.Collections' at the top.
Exit Function return

Set NewEnum = mCol.[_NewEnum]
IEnumerator newEnum = mCol.GetEnumerator()
And is there in C# something like modules (classes) ???
public class MyClass
{

}
 
G

Guest

Hi PseudoBill,

I tried the demo version of the instantcsharp doodad, but within five minutees I experienced severe doubt as to its use. Note that it can't cope with Vb.Net named arguments (not that many use them, but some -me! - do). The converter maps my arg1:=whatever to arg:== and expresses the view that much of the transliterated code contains 'invalid expression terms', the nerve!

The rest may be great, and I may have been unlucky in my experience, but I'll stick with the Reflector for now.

Regards SteveW
 
D

David Anton

Steve Wilsonwrote:
Hi PseudoBill,
I tried the demo version of the instantcsharp doodad, but within
five minutees I experienced severe doubt as to its use. Note that it
can't cope with Vb.Net named arguments (not that many use them, but
some -me! - do). The converter maps my arg1:=whatever to arg:== and
expresses the view that much of the transliterated code contains
'invalid expression terms', the nerve!
The rest may be great, and I may have been unlucky in my experience,
but I'll stick with the Reflector for now.
Regards SteveW
--
toujours gai, wotthehell wotthehell


:

Download a free VB.NET to C# converter (for instance:
www.instantcsharp.com has a free demo). Doing this stuff line by
line, case by case, is nuts.



[/quote:9ff0de7dcf]


Hi Steve:
Instant C# does convert calls to methods using named parameters. One
of our samples shows this (Samples/Unique VB Features/Named Arguments
from the context menu). Obviously, there is some case or format that
isn't working to your satisfaction - could you submit an example that
doesn't work for you?

Either reply here or contact me directly at
(e-mail address removed). We are very interested in our
users' input (even those who decide that our free Demo Edition is
sufficient for their needs - it all contributes to a better product).
If we can address a concern, we will typically have a new build
available to you within a few hours.
 

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