473,799 Members | 3,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

returning a string and bool type from a member of a class

Hi I have the method below that returns a bool, true or false depending
on if the conversion to date tiem works. It takes a string input. I am
only returning the bool but would also like to return the string message
ex.message, just wondering how to do this since I think you can only return
one thing with the function. Thanks.

public bool checkdate(Strin g s_date)
{
b_convert = true ;
DateTime dt_temp1 = Convert.ToDateT ime("1/1/1980");
try
{
dt_temp1 = Convert.ToDateT ime(s_date);
}
catch (Exception ex)
{
errormsg = ex.Message;
b_convert = false;
}
return b_convert;
}
--
Paul G
Software engineer.
May 11 '07
11 1987
On May 11, 10:51 am, Paul <P...@discussio ns.microsoft.co mwrote:
Hi I have the method below that returns a bool, true or false depending
on if the conversion to date tiem works. It takes a string input. I am
only returning the bool but would also like to return the string message
ex.message, just wondering how to do this since I think you can only return
one thing with the function. Thanks.

public bool checkdate(Strin g s_date)
{
b_convert = true ;
DateTime dt_temp1 = Convert.ToDateT ime("1/1/1980");
try
{
dt_temp1 = Convert.ToDateT ime(s_date);
}
catch (Exception ex)
{
errormsg = ex.Message;
b_convert = false;
}
return b_convert;
}
--
Paul G
Software engineer.
Why re-invent the wheel? This method already exists in the form of
DateTime.TryPar se and DateTime.TryPar seExact.

Chris

May 11 '07 #11
Paul wrote:
Hi I have the method below that returns a bool, true or false depending
on if the conversion to date tiem works. It takes a string input. I am
only returning the bool but would also like to return the string message
ex.message, just wondering how to do this since I think you can only return
one thing with the function. Thanks.

public bool checkdate(Strin g s_date)
{
b_convert = true ;
DateTime dt_temp1 = Convert.ToDateT ime("1/1/1980");
try
{
dt_temp1 = Convert.ToDateT ime(s_date);
}
catch (Exception ex)
{
errormsg = ex.Message;
b_convert = false;
}
return b_convert;
}
An alternative to the out parameter recommended by several you
could return a struct.

Arne
May 12 '07 #12

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

Similar topics

7
20375
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But , for example, when the file doesnt exists, i should not return any reference to a bad constructed object, so i need something as a NULL reference object. I suppose i could return a pointer instead, but i have some code written with references which...
3
2613
by: Pierre Espenan | last post by:
A have a long integer class. The built integer type within a conditional statement returns bool false for int i=0 and bool true for any other non zero value. I want my long integer class to have similar behavior. My class looks like this: #ifndef long_int_H #define long_int_H #include <string> using namespace std; typedef valarray<complex<double> > VCD;
5
3112
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the function below is returning a pointer to pointers who are GUID. I am trying to write a wrapper to use in my VB code and what I would prefer to do is be able to return an array of GUID. I remember (not sure) that the concept of arrays does not really...
3
2865
by: Christian Christmann | last post by:
Hi, I'm working on my first STL program. My class BitSet has three private attributes size, curbit and the STL bit_vector data which contains some bits. Here is the code for the constructors: BitSet::BitSet() :last(-1)
4
2404
by: cpisz | last post by:
At least that is what I think I want to do. What is the proper way for me to return multiple data member objects from an accessor method in my class while ensuring the data does not get changed, but allowing iteration through the data? I tryed returning a const vector but the compiler does not like the idea of my using an iterator to look through the vector down the road...I assume because an iterator acts like a pointer and allows you...
2
8524
by: Philippe F. Bertrand | last post by:
Summary - What should a C# bool map to in C++? Are return types different? I have lots of methods declared with bool parameters and bool return type which appear to work without any problems but one method in particular seems to always return true. The method is declared in C# as private static extern
5
19601
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was having a problem in the calling program. I searched online and found suggestions that I return an Array instead so I modified my code (below) to return an Array instead of an ArrayList. Now I get the message when I try to run just my webservice...
1
5555
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two other properties... bool error; string lastError; My whole class looks like this... using System;
6
2935
by: shapper | last post by:
Hello, I have a method: Roles(CultureInfo culture, RoleType? type, bool? open, bool? beginWithEmpty, string userRoles) How can I pass an empty string as userRoles? I tried: Roles(Thread.CurrentThread.CurrentCulture, RoleType.Administrator, false, true, new string)
0
9544
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
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 we have to send another system
3
2941
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.