Solved

Type Conversion, CString to longbinaray, CString to datetime

Posted on 1997-11-02
2
608 Views
Last Modified: 2013-11-20
hello,
   i'd like to know how can i convert CString to longbinary... and also CString to datetime... thanks, :) mallow
0
Comment
Question by:mallow
2 Comments
 
LVL 5

Accepted Solution

by:
dirtdart earned 20 total points
ID: 1309168
By longbinary I am assuming you mean long.  That is pretty easy.

int len;
CString Num;
long ConvertedNum;
int ct;
char temp;

len = Num.GetLength();

for(ct = 0; ct < len; ++ct)
{
    temp = Num.GetAt(ct);
    ConvertedNum = (long)(temp + 48);
    ConvertedNum *=10;
}


CString to DateTime would go something like this:

int Month;
int Year;
int Day;
int pt;
CString temp;

CString OldDate;
COleDateTime NewDate;

pt = OldDate.Find("/");
temp = OldDate.Left(pt);

//At this point use to code above for converting a CString to a long, just substitiue int for long and set Month equal to the resulting value.  Trim off the value of temp from OldDate and perform this operation twice more to get the Day and Year.  Then call COleDateTime.SetTime(M, D, Y, H, M, S);


0
 

Expert Comment

by:mmachie
ID: 1309169
to conver a cstring to a long value try:
CString num_to_convert;
long converted_num = atol( num_to_convert);

to convert the cstring to a COleDateTime you must parse out the the year, month, and day.  try using the CString::Mid() function.  convert the parsed value using atoi() function then call COleDateTime::SetDate() with the converted values.

hope this helps.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question