Properties and Constructor

S

shapper

Hello,

I create a class where I have 2 properties, Name(_Name) and
Email(_Email), and one function, Subscribe.

I would like to use my class in two ways:

Dim Object As MyClass
Object.Name = "My Name"
Object.Email = "My Email"
Object.Subscribe

OR

Dim Object As MyClass
Object.Subscribe("My Name", "My Email")

How should my Subscribe function look like?

I can use:

Function Subscribe(ByVal _Name As String, ByVal _Email As String)

Dim ClassName = _Name
Dim ClassEmail = _Email

End Function

However this is allways expecting the _Name and _Email to be passed
trought the function and not through the properties.

Do I make any sense what I am trying to do?

Thanks,
Miguel
 
S

shapper

But does that mean that I will have two functions exactly with the same
code but different "headers"? It is like a repetition?

Thanks,
Miguel
 
S

shapper

I am lost now.

You mean:

Overloads Function Subscribe()

Overloads Subscribe(_Name, _Email)

[My Subscribe function code here]

End Function

Is this what you mean?

Thanks,
Miguel
But does that mean that I will have two functions exactly with the same
code but different "headers"? It is like a repetition?

How about calling one overload in the second one?

Function Subscribe()
Subscribe(_Name, _Email)
End Function

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
 
R

Robert Haken [MVP]

Huh, you want me to learn VB.NET syntax... ;-))

I mean that instead of duplicating the code in two overloads of one method,
you can fully implement only one of them and call it from the second one
with appropriate parameters.

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz

shapper said:
I am lost now.

You mean:

Overloads Function Subscribe()

Overloads Subscribe(_Name, _Email)

[My Subscribe function code here]

End Function

Is this what you mean?

Thanks,
Miguel
But does that mean that I will have two functions exactly with the same
code but different "headers"? It is like a repetition?

How about calling one overload in the second one?

Function Subscribe()
Subscribe(_Name, _Email)
End Function

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
 
S

shapper

Please,

feel free to write in C. I also know C but I am working in VB right
now.

Thanks,
Miguel
Huh, you want me to learn VB.NET syntax... ;-))

I mean that instead of duplicating the code in two overloads of one method,
you can fully implement only one of them and call it from the second one
with appropriate parameters.

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz

shapper said:
I am lost now.

You mean:

Overloads Function Subscribe()

Overloads Subscribe(_Name, _Email)

[My Subscribe function code here]

End Function

Is this what you mean?

Thanks,
Miguel
But does that mean that I will have two functions exactly with the same
code but different "headers"? It is like a repetition?

How about calling one overload in the second one?

Function Subscribe()
Subscribe(_Name, _Email)
End Function

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
 
S

sloan

public class MySubscriber

private m_name as string = string.empty
private m_email as string = string.empty

public sub new ( n as string , em as string)
me.m_name = n
me.m_email = em
end sub



public sub Subscribe()
InterneralSubscribe(me.m_name, m_email)
End sub

public sub Subscribe ( nnn as string , emem as string)
InterneralSubscribe(nnn, ememl)
end sub

private sub InterneralSubscribe ( name as string , email as string)


if (name.length<=0) then
throw new ArgumentException (" No Name " )
end if

if (email.length<=0) then
throw new ArgumentException (" No Email" )
end if
''DO the work here
end sub


end class




Please,

feel free to write in C. I also know C but I am working in VB right
now.

Thanks,
Miguel
Huh, you want me to learn VB.NET syntax... ;-))

I mean that instead of duplicating the code in two overloads of one method,
you can fully implement only one of them and call it from the second one
with appropriate parameters.

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz

shapper said:
I am lost now.

You mean:

Overloads Function Subscribe()

Overloads Subscribe(_Name, _Email)

[My Subscribe function code here]

End Function

Is this what you mean?

Thanks,
Miguel
But does that mean that I will have two functions exactly with the same
code but different "headers"? It is like a repetition?

How about calling one overload in the second one?

Function Subscribe()
Subscribe(_Name, _Email)
End Function

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
 

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