Wrox Programmer Forums
|
BOOK: Ivor Horton's Beginning Visual C++ 2010
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2010 by Ivor Horton; ISBN: 9780470500880
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2010 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2012, 11:43 PM
Authorized User
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date and time

Hello,

I wonder if someone has been using date and time.

The pre-processor is <time.h>. I can print the date and the time which is not too difficult but I need to get the ‘day of year’, that is the number of days since January 1st (0 to 365).

The way to get this is to use ‘tm_yday’ , but I had no success so far.

Thank you for any help,

Regards

com64
 
Old July 13th, 2012, 12:47 AM
Authorized User
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Anyone having experience with date and time is welcome to jump in here. I am just replying because I want to see if I can jump ahead of my experience level and figure it out.

com64,

I would like to try my hand at this too if no one else provides a solution. A few questions are in order.
  1. What version of Visual C++ are you using?
  2. Is this a win32 console program or some other type?
  3. When you build the program, are there any warnings in the output window? Warnings will still allow the program to compile and run, but your output may not be what you want. To be sure build the solution again using these instructions.
    • Click build.
    • Choose rebuild solution.
    This will show all warnings. Simply building will not display warnings which were displayed previously. If there are warnings, please post them here enclosed in code tags.
  4. Can you post your code enclosed in code tags for examination?

regards,
drpepper
 
Old July 13th, 2012, 02:29 AM
Authorized User
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,
That was a quick reply. Thank you.
Also thank you for the instructions for the new thread.
Answering tyour questions on #2:
1. I use Microsfotf Visual C++ 2010 Express, the free version. (Version 10.0.30319.1). I do not have any of the very expensive Microsoft Visual Studios, as you already mentionned yourself. At this stage I cannot justify the expense.
2. Using the 32 Console.
3. There are no warings, so I could assume the code is OK. The real problem is to re-compile after saving some changes.
4. Here is the code. On the original code I did put the time at 1.25 and on the modified version the time is 6:02 but on the console the time stays at 1:25...
Code:
// datetime_1.cpp : Writes date and time (UTC)

#include "StdAfx.h"
#include <stdio.h>
#include <time.h>

void main()
{

SYSTEMTIME st;                               //uses SYSTEMTIME 
GetSystemTime (&st);
printf ("\n\n");
printf("Title of programme: datetime_1");    //title
printf ("\n\n");

printf("Today's date is:\n");
printf("Year: %d\n", st.wYear);
printf("Month: %d\n", st.wMonth);
printf("Day: %d\n\n\n", st.wDay);

printf("The UTC time is now: \n");
printf("Hour: %d\n", st.wHour);
printf("Minute :%d\n", st.wMinute);
printf("Second: %d\n\n\n", st.wSecond);

printf ("\n\n");
printf ("New version at 6:02");              // shows time of new version
printf ("\n\n");

return 0;
}
Best regards

com64
 
Old July 13th, 2012, 11:19 AM
Authorized User
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Good morning com64,

I inspected the code you posted before attempting to build the solution. Four things stood out. (Note: In all the scenarios below, I used both Use Unicode Character Set and Not Set properties for testing.)

The first is not essential for successful build and run. It is merely my attempt to determine how you set the solution up. The code on line 3 gave me the indication that you did not use an empty project.
Code:
#include "StdAfx.h"
The second is syntax that caught my eye. (StdAfx versus stdafx) The syntax could possibly create an error. I opened an empty project to test my theory. I pasted your code in the text editor and attempted to build it and received compiler errors. I then changed the syntax of line 3 to all lower case and received the same compiler errors. The excerpted error was "cannot open StdAfx (or stdafx): no such file or directory".

This seemed to confirm that you are using compiled headers. This is not a criticism. It is merely my way of determining exactly what kind of project is being used. I use empty projects for the purpose of learning which preprocessor directives are essential to provide the facilities to support the code in my programs. My personal experience is that stdafx will not work without supporting code in an empty project.

The third thing that caught my eye was line 10.
Code:
SYSTEMTIME st;                               //uses SYSTEMTIME
I saw no definition or declaration of SYTEMTIME. I wondered if time.h included the definition or declaration; so I printed out the entire header file for inspection. Unless I missed something, SYSTEMTIME is not in time.h. My best guess was that there would be a compiler error.

To test my theory I opened a new project and used precompiled headers. I pasted the your code again and attempted a build. I received compiler errors. The paraphrased error is "SYSTEMTIME - undeclared identifier".

Last, but not least, I saw no reference to tm_yday, which you referenced in another thread, outside of the time.h header.

I now have some great big question marks floating around in my head.
  • Does your code compile and run properly with the exception of the day of the year?
  • Did you post your entire code?
  • Did you manually type the code or copy/paste it? My typing skills are not the greatest in the world; so I use copy/paste to avoid errors.
  • If your code compiles and runs, why can't get it to compile and run? Could it be that the code you posted is not stand alone code, but code that is called by another function or program as part of a larger project or solution?
  • Is my newbie status of not understanding classes with all their nuances the reason why I cannot grasp the error source?
  • Are you using build or rebuild after making changes?
  • What are the compiler errors you are receiving?

Maybe you can teach me something here... ??!!

regards,
drpepper

Last edited by drpepper; July 13th, 2012 at 11:25 AM..
 
Old July 14th, 2012, 03:22 AM
Authorized User
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear drpepper,

Many thanks for looking at my mistakes and errors.
I think one is always punished for his crimes…that is my case trying to run before walking. I think I should leave that “time” business alone for the time being and go back to the book like a good school boy, avoiding hazardous adventures… I shall return to it later after acquiring some more knowledge…End of the holydays, back to school.

I do receive notice of your postings by email, which is quite convenient. Do you receive similar notice? If you don’t and if you would like to receive such notice, please let me know and please tell me know it is done. (If it has to be done at my end). Thank you.

One last question: Is it possible to use larger fonts on the editor? Mine are very small and difficult to read for old eyes.

Best regards

com64
 
Old July 14th, 2012, 09:31 AM
Authorized User
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hi com64,

You're welcome. It's too bad I don't have a deeper understanding. Maybe I could have provided some real help. I use the interaction of forums to expand my learning possibilities.

My best guess is that your challenges in writing the code of your choice is buried somewhere in the understanding of classes (inheritance, constructors, destructors, overloading, etc.) and functions (prototypes, passing by value, passing by pointers, and passing by reference). There is an enormous amount of foundational concepts which these build upon. C++ is a very complex language, but its mastery allows great freedom in performing operations which are not as effective in other languages. For example, did you know that you can create, copy, move, and delete directories in C++?

email notification ... Yes, I know about email notification for posts (and even entire forums). This is a feature I look for in every new forum I enter. Thank you for the offer to help me with notifications. Email notification was included in the instructions I posted for starting a new thread. You can manipulate the notification options in either a thread you are using or through your profiles.

Changing font sizes ... (a drum roll, please ... just kidding ... I hope you have the insane sense of humor that I have...)
for the text editor:
I did a little poking around to find an answer for you. Click tools. From the menus choose environment>font and colors. In the window that opens look on the right side. There is a box for size with a drop down arrow. Font sizes up to 24pt are available. You can preview the result in the box at the lower right (labeled sample). Click OK to apply. I played around with it using one of my recent solutions and found that the larger fonts will word wrap for you when necessary. Unfortunately I did not find the same option for the solution explorer window or the output window.
for your browsers:
You may already know this one, but I am including it just in case you have not discovered it yet. I have tested it in Internet Explorer, Firefox, and Google Chrome.
  • Press Ctrl and + at the same time to enlarge (zoom in).
  • Press Ctrl and - (minus) at the same time to decrease size (zoom out).
  • Press Ctrl and 0 (zero) at the same time to return to default size.
A word of warning is necessary here. When you zoom in in a browser, the content may flow off the right side of the window. The horizontal scroll bar must be used to view the part of the window which is off screen. However, there is a trick which many people don't know. Check the scroll wheel on your mouse. If it will tilt left and right, you can press the scroll wheel left or right to scroll left or right.

I hope you find this helpful. Please post back with your results or more questions.

regards,
drpepper

EDIT: See post #7

Last edited by drpepper; July 14th, 2012 at 10:24 AM..
 
Old July 14th, 2012, 10:23 AM
Authorized User
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

addendum to post #6:

If you tell me which Operating System you use, I can guide you to some options offered by Windows. It is possible to either magnify portions of the active window or increase size of display system-wide. You can always return to default settings if you don't like the results.

regards,
drpepper
 
Old July 15th, 2012, 09:57 PM
Authorized User
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear drpepper,
Many thanks for the instructions to change the size of the fonts on the editor. Much more pleasant for old eyes now.
I am using Windows 7 and sometimes I miss the good'ol XP...
Still progressive slowly throught the book. But as all criminals always return to the scene of their crime, I had a last go at that time and date stuff. This time it compliles and work well but I am going to leave it for the time being.
Here is the code. I wonder if it will complie on your machien.
Code:
// datetime_5.cpp written on 15/7 at 16:51
// shows date and local time. 

#include "stdafx.h"
#include <time.h>

void main()
{
char dateString [9];
char timeString [9];

printf ("\n\n");
printf ("Title: \'datetime_5.cpp\'");

printf ("\n\n");
_strdate_s (dateString);
printf ("The date today  is :  %s \n\n\n", dateString);

_strtime_s (timeString);
printf ("The local time is : %s \n\n\n", timeString);

}
Best regards
com64
 
Old July 16th, 2012, 11:50 AM
Authorized User
 
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Good morning, com64

You are quite welcome. I am happy to hear that you now have larger fonts in the text editor. Let's move to Windows.

Revisiting the information I provided on browsers may be prudent before addressing the operating system features. You will probably be more pleased with using the hot key combinations in browsers than with the OS features. The browsers offer a horizontal scroll bar at the bottom of the window to view the portion of the window which may extend off screen. Check out your mouse as described earlier to facilitate horizontal scrolling. Testing I performed before composing instructions revealed that the operating system visual aids do not include the horizontal scroll feature.

To access the features provided by Windows 7, press the start button. Then navigate: all programs> accessories> ease of access. Of the several entries displayed under ease of access, start with magnifier and ease of access center.

magnifier:
There are several options which you can fine tune to your liking. The two which look the best to me are the full screen and lens features. The full screen can enlarge the active window beyond the capability to view everything. This is the part I referred to when writing about horizontal scrolling. The lens can be used like a hand held magnifying glass. It is a little cumbersome, but it is better than squinting to view content.

I strongly recommend clicking on all buttons, menus, etc. to explore the options available to you. You may find something which is helpful to you.

ease of access center:
It will be much easier for you to explore this section than for me to write instructions. The time invested to check out the links and options available may yield you helpful tools. Take the time to check out everything. There may be something hidden in the options which provide you with exactly what you need.

installed programs:
Many (not all) Microsoft and third party programs have a zoom feature included as part of the program. It is usually found under the view tab of the tool bar. A little poking around in your installed programs may be rewarding.

re: your code
Your code compiles and runs on my machine. I used win32 console project with precompiled headers, deleted default code in the editor, and pasted your posted new code in the editor. I noted the variable declarations which were not in the code you posted earlier. I believe that was the reason I could not run the first code.

In closing, I am real curious how well the Windows features work for you. Please post back with results, problems, etc.


regards,
drpepper

Last edited by drpepper; July 16th, 2012 at 11:54 AM.. Reason: typo/ grammar
 
Old July 23rd, 2012, 09:01 PM
Authorized User
 
Join Date: Jun 2012
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear drpepper,

Many thanks for the info on accessibility on Windows. I did not know there was so much there.

Still pushing along slowly through the book.

I had a small win… I must have told you my aim in C++ is to replace my parallel port interface with a USB interface. I have just received 2 such interfaces, one as a kit that has to be assembled, the other the ‘Arduino’ interface. Both use C++ as programming language. That should be fun.

Best regards

Com 64





Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Time Field not displaying Date and Time webmeister Access 2 January 31st, 2011 12:49 AM
Extracting Time from Date/Time Navy1991_1 XSLT 2 June 3rd, 2008 12:03 PM
date and time in EST time zone anboss XSLT 1 May 21st, 2008 01:42 PM
How to retieve only the date not date and time debjanib ASP.NET 1.0 and 1.1 Professional 2 July 25th, 2006 01:10 PM
insert system date. no date and time jimmy Access VBA 6 November 20th, 2003 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.