9 Replies - 828 Views - Last Post: 10 February 2010 - 06:49 PM Rate Topic: -----

#1 Birdo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-January 10

Builder5 User Needs Help With Simple Program

Post icon  Posted 24 January 2010 - 09:24 AM

I checked Intermediate because I studied programming for several years, however it's been a long time since I've sat at the computer, coding for homework or practice, or curiosity. Now I could actually put to use a simple program that is a punch clock. Just a few components are needed: EmployeeName, password, timeIn, and timeOut. Right now I'm trying to find the correct function to write name, time-in and time-out to file (record) when the PunchIN/PunchOUT button is clicked. A simple text file would suffice or anything that could be used to print a report at the end of the week. It would be nice to be able to view values any time during program execution. I am using BorlandC++ Builder5.
Most of my classwork was with console applications but now I'm using the VCL and dragging and dropping components onto a form. I have the components employee, password, and PunchIn and PunchOUT on the form. I've hard-coded names into the employee list.
I need to set passwords and connect them with their employee so that a message displays if they don't match.
I would like to be able to administer so I could add a name or adjust times.
Thanks for any suggestions.

Is This A Good Question/Topic? 0
  • +

Replies To: Builder5 User Needs Help With Simple Program

#2 Splatocaster  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 51
  • View blog
  • Posts: 182
  • Joined: 22-December 09

Re: Builder5 User Needs Help With Simple Program

Posted 24 January 2010 - 09:33 AM

Im not sure how you would do it with the UI api your using, however here are some general suggestions.
First, ask the user their name, and store into a std::string.
Than, take the password into a std::string.
Repeat for all questions.
http://www.cplusplus...tutorial/files/ has a great tutorial on file input/output.
Try to mess around yourself and get this to work. If you have any particular problems, make a more specific post.

Good luck with this project!
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Builder5 User Needs Help With Simple Program

Posted 24 January 2010 - 10:45 AM

...Borland Builder Eh? Well I suppose the big problem with helping you is that VCL is not really documented out on the web much (and what documentation exists is mostly for Delphi developers).

You might find this site pretty helpful.
Was This Post Helpful? 0
  • +
  • -

#4 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1362
  • View blog
  • Posts: 4,716
  • Joined: 19-February 09

Re: Builder5 User Needs Help With Simple Program

Posted 25 January 2010 - 07:37 PM

View PostBirdo, on 24 Jan, 2010 - 05:24 PM, said:

... Right now I'm trying to find the correct function to write name, time-in and time-out to file (record) when the PunchIN/PunchOUT button is clicked. A simple text file would suffice or anything that could be used to print a report at the end of the week. ...

Hi, I would create a Class to handle writing records.
Writing it in its own header/source file(s) (for tidiness among other reasons).
Then create an instance of the Class in the Form Class.
In a Button Event function (onclick), the class can be accessed and
name can be passed to a member function.

View PostBirdo, on 24 Jan, 2010 - 05:24 PM, said:

... It would be nice to be able to view values any time during program execution. ...

You could use a Memo component for this, and using Lines->Add().
Was This Post Helpful? 0
  • +
  • -

#5 Birdo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-January 10

Re: Builder5 User Needs Help With Simple Program

Posted 27 January 2010 - 02:33 PM

Thanks for all the replies. Creating a class to do the file processing is probably wise, but I'm so rusty at class creation and I just want to see this thing work now (prototype). Here's where I am: Form1 has Combobox1 with employee names, Editbox1 for passwords, and a "PunchIn" Button1. I also have Editbox2 displaying the time punched in. At the same time a dialog box opens and asks the user to save to file (PunchIn.txt is the default file to save to). I'd rather not let the users see the file they're saving to or have to click another button. How can I just save to this file without the Windows save dialog box? I will also need help on matching up passwords with employees before they are allowed to punch in. Thanks so much.
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1362
  • View blog
  • Posts: 4,716
  • Joined: 19-February 09

Re: Builder5 User Needs Help With Simple Program

Posted 27 January 2010 - 05:57 PM

View PostBirdo, on 27 Jan, 2010 - 10:33 PM, said:

... At the same time a dialog box opens and asks the user to save to file (PunchIn.txt is the default file to save to). I'd rather not let the users see the file they're saving to or have to click another button. How can I just save to this file without the Windows save dialog box? ...


Hi, somehow you have a save file dialog on your form,
by the sound of it. You can delete this since you dont want the
user to use it.
(You could use hidden components to do roughly what you want,
but it is probably better to use code.)

Double-Click on your "PunchIn" button (in the Form Designer).
This should bring up an empty function (in the editor),
called Button1Click(). This function/code will be executed when
the button is clicked.

Add the following code (there maybe slight naming differences).
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  using namespace std;
  ofstream punchfile;

  punchfile.open ("PunchIn.txt", ios::out | ios::app );
  punchfile << "Writing this to a file. " << Edit1->Text.c_str() << endl;
  punchfile.close();

}



At the top of this file under #include <vcl.h> add
the two stream header filenames.
#include <vcl.h>
#include <iostream>
#include <fstream>


Have a look at that and see how you get on.
Was This Post Helpful? 0
  • +
  • -

#7 Birdo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-January 10

Re: Builder5 User Needs Help With Simple Program

Posted 06 February 2010 - 08:31 PM

Thanks #define - That was exactly what I was looking for. It works! Now we're writing comma-separated lines of name and time-in to a file . I'd like to re-write to this file the times-out. Meaning I'd like to go back to the line say, Walter Flores,7:00am and put the time-out on the end of that line so it's Walter Flores,7:00am,4:00pm . Anyone know offhand how this is done?

This post has been edited by Birdo: 06 February 2010 - 08:38 PM

Was This Post Helpful? 0
  • +
  • -

#8 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1362
  • View blog
  • Posts: 4,716
  • Joined: 19-February 09

Re: Builder5 User Needs Help With Simple Program

Posted 07 February 2010 - 12:57 PM

View PostBirdo, on 07 February 2010 - 04:31 AM, said:

I'd like to re-write to this file the times-out. Meaning I'd like to go back to the line say, Walter Flores,7:00am and put the time-out on the end of that line so it's Walter Flores,7:00am,4:00pm .


I can think of two ways of doing this, off the top of my head.

First way, as you are suggesting, go back to the line and write.
This would require the record to be written, initially, with a fixed width,
and blank spaces left for the time-out to be added/overwritten.
Could use - #include <iomanip> - stream manipulator setw() perhaps setfill().

The record/name would have to be found, either searched
or using index list. Since the record is fixed width,
calculating start of records/fields is not too difficult.
Could use - #include <fstream> - seekp, seekg, tellp, tellg.

Second way, continue with present method of adding records to file.
Write another program to collate the data, into another datafile.
This method is slightly simpler.

Another thing, to consider, is how you handle different days/dates.
Was This Post Helpful? 0
  • +
  • -

#9 Birdo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 24-January 10

Re: Builder5 User Needs Help With Simple Program

Posted 10 February 2010 - 09:49 AM

Thanks for the help #define. I'm still in the testing stage:
I now have two files - an input file ("punchIn.txt") and an output file
("poutfile.txt"). Users append the names and times-in to
input file. When the user punches out, the program reads from
this file to a struct which adds a time-out, then writes the name, date, time-in and time-out to output file.
It works now with one record. I will need to declare an array of structs and do some processing so that I get all the records done.
Then I'll need to work on password validation.

This post has been edited by Birdo: 10 February 2010 - 09:51 AM

Was This Post Helpful? 0
  • +
  • -

#10 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1362
  • View blog
  • Posts: 4,716
  • Joined: 19-February 09

Re: Builder5 User Needs Help With Simple Program

Posted 10 February 2010 - 06:49 PM

That's good!

For interacting with user you might find ShowMessage() or TApplication::MessageBox functions useful, at some point.
Don't know if you have found them or not.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1