473,503 Members | 4,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

basic class question

I have a class with methods that return an enum value to the main page.
I have the enum declared both in the class and the main page so that I
can read the value that is returned from each class method. Here is the
enum and code calling the class method on the main page. Is this the
right way to go about this (converting the returned value etc) or is
there a more clever way to do it?

public enum VResult
{
Valid = 0,
Invalid = 1
}

....

creditcard ccPackage = new creditcard();

VResult vrValidCardType =
(VResult)ccPackage.Validate_Card_Type(strCardTypeP ackage);

if (vrValidCardType == VResult.Invalid)
{
//do stuff
}

Thanks,

Mike


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
4 898
Declare the enum in the same assembly as the class (but don't make it part of the class) and mark it as public, then just have the method signature as

public VResult ccPackage.Validate_Card_Type(string cardType);

Now you code doesn't need the cast:

VResult vrValidCardType - ccPackage.Validate_Card_Type(strCardTypePackage);
if( vrValidCardType == VResult.Invalid )
...

You don't need to declare the enum in two locations

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<OR**************@TK2MSFTNGP10.phx.gbl>

I have a class with methods that return an enum value to the main page.
I have the enum declared both in the class and the main page so that I
can read the value that is returned from each class method. Here is the
enum and code calling the class method on the main page. Is this the
right way to go about this (converting the returned value etc) or is
there a more clever way to do it?
Nov 16 '05 #2

Richard,

This would mean that if I make a DLL and reference it from my main page,
I would gain access to the enum that way? Why are you prefixing the
method in the class with the instance name though?
Regards,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi,
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:OR**************@TK2MSFTNGP10.phx.gbl...
I have a class with methods that return an enum value to the main page.
I have the enum declared both in the class and the main page
Declare it only once, if you could declare it twice is cause either they
are in different namespaces or one is part of a class, in any way they are
DIFFERENTS
That's why you have to cast it, otherwise you would get an error.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

so that I
can read the value that is returned from each class method. Here is the
enum and code calling the class method on the main page. Is this the
right way to go about this (converting the returned value etc) or is
there a more clever way to do it?

public enum VResult
{
Valid = 0,
Invalid = 1
}

...

creditcard ccPackage = new creditcard();

VResult vrValidCardType =
(VResult)ccPackage.Validate_Card_Type(strCardTypeP ackage);

if (vrValidCardType == VResult.Invalid)
{
//do stuff
}

Thanks,

Mike


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #4
The instance name on the method declaration was a typo :-)

Yes you could gain access to the enum that way - although I assumed (obviously incorrectly) that the class was already in a different assembly. If it isn't, simply declare the enum outside of the scope of the class and change the code as I stated before (without the erroneous instance name on the method of course ;-) )

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
Richard,

This would mean that if I make a DLL and reference it from my main page,
I would gain access to the enum that way? Why are you prefixing the
method in the class with the instance name though?
Regards,

Mike

Nov 16 '05 #5

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

Similar topics

1
1232
by: Bob | last post by:
Try the following code class basic { public: virtual void one()=0; }; class derived1:public basic { public:
4
2215
by: Ramesh | last post by:
hi, Let me ask some basic questions. Can anybody explain me about the following questions: 1. When we have to create sn key? Whenever we compiled Component we have to create or it is a one time...
5
1171
by: Paul Bromley | last post by:
I have written a similar enquiry to this newsgroup, but had no responses - hence I will rephrase it with the hope that someone will answer. I am new to using Classes, but trying hard to get the...
13
15524
by: Pete | last post by:
I'm cross posting from mscom.webservices.general as I have received no answer there: There has been a number of recent posts requesting how to satisfactorily enable BASIC authorization at the...
5
1800
by: Aussie Rules | last post by:
Hi, Having a mental block on this one. Have done it before but can't rack my brain on how... I have an object, with a bunch on property, and I add that object to a combo box. I want the...
18
2371
by: Ann Scharpf via AccessMonster.com | last post by:
I am not sure which would be the best place to post this question, so I'm posing it here with Access general questions. I have reached the point many times in Word and in Access where my ignorance...
4
1709
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, ...
14
1826
by: MartinRinehart | last post by:
Working on parser for my language, I see that all classes (Token, Production, Statement, ...) have one thing in common. They all maintain start and stop positions in the source text. So it seems...
9
1588
by: Peskov Dmitry | last post by:
It is a very basic question.Surely i got something wrong in my basic understanding. //Contents of file1.cpp using namespace std; #include <iostream> template <typename T> class my_stack;
3
1928
by: Scott Stark | last post by:
Hello, I'm trying to get a better handle on OOP programming principles in VB.NET. Forgive me if this question is sort of basic, but here's what I want to do. I have a collection of Employee...
0
7357
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...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.