Solved

Type Conversion, CString to longbinaray, CString to datetime

Posted on 1997-11-02
2
604 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 42
Shell script to login to remote m/c and execute commands 10 78
scoreUp challenge 14 63
wordmultiple challenge 12 140
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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