Help needed in vb-c# translation

T

tiger79

Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a method out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I just
cant grasp which one(s) I should be using...

Thanx...
 
N

Nicholas Paldino [.NET/C# MVP]

tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.
 
T

tiger79

Great only I got a question about the property declaration :
the get method is quite straight-forward but how about the set-method (or
part) ? Because looking at ur code it seems to me u assign that mstrString a
value but where does that value come ? Like in a method :

public void ChangeSomething(string newValue)
{
something = newValue
}

here I send the string newValue so it knows what to assign to something.
How does it work in ur example ?
Thanx again, the other info has been very usefull !!! :D


Nicholas Paldino said:
tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a method out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I just
cant grasp which one(s) I should be using...

Thanx...
 
N

Nicholas Paldino [.NET/C# MVP]

tiger79,

When in the set section of your property declaration, "value" is a
keyword. This is a variable which represents the value passed in from the
right-hand side.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
Great only I got a question about the property declaration :
the get method is quite straight-forward but how about the set-method (or
part) ? Because looking at ur code it seems to me u assign that mstrString a
value but where does that value come ? Like in a method :

public void ChangeSomething(string newValue)
{
something = newValue
}

here I send the string newValue so it knows what to assign to something.
How does it work in ur example ?
Thanx again, the other info has been very usefull !!! :D


message news:[email protected]...
tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a
method
out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I just
cant grasp which one(s) I should be using...

Thanx...
 
T

tiger79

ok, i'll give a short example :

this is the vb code :
Public Property Get AttributeId() As String
' Returns Identifier of the attribute
AttributeId = mAttributeID
End Property

Friend Property Let AttributeId(ByVal vNewValue As String)
mAttributeID = vNewValue
End Property

as U can see the property is divided in two, a Get and a Let property. The
one is public the other is friend. I made the following code in C# :
public string GetAttributeId()

{

return pAttributeId;

}

internal void SetAttributeId(string vNewValue)

{

pAttributeId = vNewValue;

}



hehehe... sorry for the formatting...

Anyways now I was wondering if this is any good ? Or that I should be
implementing the property-way u explained ?

Thanx...



Nicholas Paldino said:
tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a method out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I just
cant grasp which one(s) I should be using...

Thanx...
 
N

Nicholas Paldino [.NET/C# MVP]

tiger79,

In general, you have to declare your property like this:

public strinct AttributeId
{
get
{
return pAttributeId;
}
set
{
pAttributeId = value;
}
}

However, you want to set different accessibility levels, which is not
allowed currently. The next version of C# will support this, and the syntax
for what you want is as follows:

public strinct AttributeId
{
get
{
return pAttributeId;
}
internal set
{
pAttributeId = value;
}
}

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
ok, i'll give a short example :

this is the vb code :
Public Property Get AttributeId() As String
' Returns Identifier of the attribute
AttributeId = mAttributeID
End Property

Friend Property Let AttributeId(ByVal vNewValue As String)
mAttributeID = vNewValue
End Property

as U can see the property is divided in two, a Get and a Let property. The
one is public the other is friend. I made the following code in C# :
public string GetAttributeId()

{

return pAttributeId;

}

internal void SetAttributeId(string vNewValue)

{

pAttributeId = vNewValue;

}



hehehe... sorry for the formatting...

Anyways now I was wondering if this is any good ? Or that I should be
implementing the property-way u explained ?

Thanx...



message news:[email protected]...
tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a
method
out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I just
cant grasp which one(s) I should be using...

Thanx...
 
T

tiger79

Great, armed with this new information I will try to get my API to work :D
thanx again, especially for the (lightning)fast responses...

i will definiely meet u again on this newsgroup, im kinda of an infinite
hole of questions ;)

Nicholas Paldino said:
tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a method out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I just
cant grasp which one(s) I should be using...

Thanx...
 
T

TheNedMan

C# and .net in general allow only non-parametized properties, so your
example must be turned into a regular method.

'Friend' is 'internal'

'Variant' is 'object'

'Modules' become internal-scope classes with static methods and
properties.
 
J

Jimi

You'll probably have many more questions, so pick up a vb to c#
converter:

Instant C#
V#
C-Sharpener
VBConversions
etc.

Instant C# is probably the best, but it is strictly a VB.NET to C#
converter, not VB6 to C#.
 
T

tiger79

hhmm... seems like the internal set wont work : modifiers cannot be placed
on property or event accessor declarations :(

Nicholas Paldino said:
tiger79,

In general, you have to declare your property like this:

public strinct AttributeId
{
get
{
return pAttributeId;
}
set
{
pAttributeId = value;
}
}

However, you want to set different accessibility levels, which is not
allowed currently. The next version of C# will support this, and the syntax
for what you want is as follows:

public strinct AttributeId
{
get
{
return pAttributeId;
}
internal set
{
pAttributeId = value;
}
}

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
ok, i'll give a short example :

this is the vb code :
Public Property Get AttributeId() As String
' Returns Identifier of the attribute
AttributeId = mAttributeID
End Property

Friend Property Let AttributeId(ByVal vNewValue As String)
mAttributeID = vNewValue
End Property

as U can see the property is divided in two, a Get and a Let property. The
one is public the other is friend. I made the following code in C# :
public string GetAttributeId()

{

return pAttributeId;

}

internal void SetAttributeId(string vNewValue)

{

pAttributeId = vNewValue;

}



hehehe... sorry for the formatting...

Anyways now I was wondering if this is any good ? Or that I should be
implementing the property-way u explained ?

Thanx...



message news:[email protected]...
tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows
classes
in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is not tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following things :
- property (i guess there is nothing like it and i'll just make a method
out
of it)
- friend (as in Friend Property Let LimitHeigh(ByVal vNewValue as Variant)
- Variant (as in the same example up here, which as far as I have found
should be called Object from now on)

I'd also like to know with what I can compare Modules and Class Modules.
I've been reading about Component, Interace and Abstract classes but I
just
cant grasp which one(s) I should be using...

Thanx...
 
N

Nicholas Paldino [.NET/C# MVP]

tiger79,

As I indicated, the "internal set" syntax is slated for the next release
of C#.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
hhmm... seems like the internal set wont work : modifiers cannot be placed
on property or event accessor declarations :(

message news:[email protected]...
tiger79,

In general, you have to declare your property like this:

public strinct AttributeId
{
get
{
return pAttributeId;
}
set
{
pAttributeId = value;
}
}

However, you want to set different accessibility levels, which is not
allowed currently. The next version of C# will support this, and the syntax
for what you want is as follows:

public strinct AttributeId
{
get
{
return pAttributeId;
}
internal set
{
pAttributeId = value;
}
}

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

tiger79 said:
ok, i'll give a short example :

this is the vb code :
Public Property Get AttributeId() As String
' Returns Identifier of the attribute
AttributeId = mAttributeID
End Property

Friend Property Let AttributeId(ByVal vNewValue As String)
mAttributeID = vNewValue
End Property

as U can see the property is divided in two, a Get and a Let property. The
one is public the other is friend. I made the following code in C# :
public string GetAttributeId()

{

return pAttributeId;

}

internal void SetAttributeId(string vNewValue)

{

pAttributeId = vNewValue;

}



hehehe... sorry for the formatting...

Anyways now I was wondering if this is any good ? Or that I should be
implementing the property-way u explained ?

Thanx...



"Nicholas Paldino [.NET/C# MVP]" <[email protected]>
wrote
in
message tiger79,

In order to declare a property in C#, you need to do the following:

public string MyProperty
{
get
{
return "hello";
}
set
{
// mstrString is a field on the class.
mstrString = value;
}
}

Basically, it is of the form:

<accessiblity level> <type of property> <property name>
{
get
{
<code to get property value>
}
set
{
<code to set property value>
}
}

As for friend, use the internal keyword, it basically allows classes
in
the same project to access that field.

Use an Object for variant types, it can store anything in it.

If you have code in a Module, then you should probably create a class,
and then have the methods of the class be static (this way, it is
not
tied
to any one instance, like functions in a module are not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi everyone,
i'm porting some api's from vb code to c# code.
Now i was wondering how i could be translating the following
things
but
 

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