Visual C++ records

Started by
24 comments, last by bigjoe11a 16 years, 3 months ago
Quote:
Your ample doesn't required an record ID. Like the others were saying. Can I ask why you didn't add one. Or is there some thing else that I missed.

Well I didn't see any need for it in a simple phone book like this, and as everything else in programming, if you don't use it, skip it.

The gotoxy function looks ok. You can use it anywhere in your code to position the cursor. Printing of text will continue from there as normal. Note that the X and Y arguments represent rows and columns, not pixels.

Its pretty much the same with colors. You can change the text color anywhere in the code like this:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);

From then on the text will be green.
Personally I think the colors is a bit dark so I usually add some intensity to them:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);


The functions used to change colors and cursor position is part of the windows console functions more info on those
Note that you will have to include the windows header at the top of your code to use these functions.
#include <windows.h>


Quote:
Any ideas form you would be great and again thanks for your sample.

Your welcome
Advertisement
Original post by pulpfist
Quote:
Your ample doesn't required an record ID. Like the others were saying. Can I ask why you didn't add one. Or is there some thing else that I missed.

Well I didn't see any need for it in a simple phone book like this, and as everything else in programming, if you don't use it, skip it.

Ok, Thats find. I thought it was required

Quote:
The gotoxy function looks ok. You can use it anywhere in your code to position the cursor. Printing of text will continue from there as normal. Note that the X and Y arguments represent rows and columns, not pixels.


Ok, any way no. sorry that not what I was trying to say. I mean is that I can't get it to work. All I get is errors. If you wanted a list of the errors. I can paste then for you.

Quote:
Its pretty much the same with colors. You can change the text color anywhere in the code like this:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
From then on the text will be green.
Personally I think the colors is a bit dark so I usually add some intensity to them:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

The functions used to change colors and cursor position is part of the windows console functions more info on those
Note that you will have to include the windows header at the top of your code to use these functions.
#include <windows.h>




Ok. I keep for getting that I have to state just what I want. How about an easy way to add colors.

instead of this line
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

how about using some thing like this
TextColor(#) // The # refers to a number of the color.
TextBackGround(#) // same as above

It would be hard for me to remember a line that long and it would make a mess of things.





Quote:
Ok, Thats find. I thought it was required

Its all up to you really. You are the one putting the stakes here.

If you look at the deleteEntry function you will see that it iterates through the book and deletes the first entry it finds that matches the name and bails out after that. So the questions arises; what if there are more entries with the same name? Should they be deleted? Did we intend to delete the last entry and not the first?
When trying to solve these issues, having a unique ID for each entry could come in handy.

While I'm at it, the findEntry function has a break statement in the loop that will make it bail out after finding an entry. This was a bad idea. If we simply remove the break statement it will continue to list more entries that matches the name.


Quote:
All I get is errors. If you wanted a list of the errors. I can paste then for you.

Yes always do that. Thats the best way to get answers around here =)


Quote:
Ok. I keep for getting that I have to state just what I want. How about an easy way to add colors.

instead of this line
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

how about using some thing like this
TextColor(#) // The # refers to a number of the color.
TextBackGround(#) // same as above

Well Microsoft decided that it should look like this
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
However, C++ has a lot of ways for us to make shortcuts ourself.

You could for example make a wrapper function at the top of your code somewhere
void TextColor(short color){    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);}

From then on you could change the color like this
TextColor(FOREGROUND_GREEN);

It turns out that FOREGROUND_GREEN is a synonym for a number.
You can try replacing it with a number and see what color you get, eg.
TextColor(5); should work.



I did write an overloaded operator once to make switching between colors easy with the cout object.
It looks like this:

First we create a new data type to represent the colors
enum ConsoleColor{  fgGreen = FOREGROUND_GREEN,  fgRed = FOREGROUND_RED  // more colors...};


Then we overload the << operator for our new data type
ostream& operator << (ostream& out, ConsoleColor& color){    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);    return out;}


Now, we can switch colors *on the fly* like this
cout << fgGreen << "This line is green " << fgRed << "This line is red" << endl;


Just a funny little thing =)

Anyway, the bottom line is that we can make wrapper functions or macros to make things easier, but we can't avoid using the SetConsoleTextAttribute function all together. At least not that I know of.
Original post by pulpfist
Quote:
Ok, Thats find. I thought it was required

Its all up to you really. You are the one putting the stakes here.

If you look at the deleteEntry function you will see that it iterates through the book and deletes the first entry it finds that matches the name and bails out after that. So the questions arises; what if there are more entries with the same name? Should they be deleted? Did we intend to delete the last entry and not the first?
When trying to solve these issues, having a unique ID for each entry could come in handy.

While I'm at it, the findEntry function has a break statement in the loop that will make it bail out after finding an entry. This was a bad idea. If we simply remove the break statement it will continue to list more entries that matches the name.


Ok, I will. any if it's a option to have records setup with an id number that would be ok. When ever you have time.

Any way I wanted to tell you that your color idea works like a charm.
TextColor(15); // = High while.

Oh, and I took out an line that I wasn't using and gotoxy(x,y) works great.
Now my menu looks better.

Any way, Thanks again. I owe you one. and now to move things a long.

Does C++ support Random access files too. I have done programing in pascal. I have all ways like that option.


Look, If theres any thing I can do for you. Let me know. I have a web site and run a BBS too. I guess thats why I want to learn C++. To Replace the BBS software I'm running now. With my Own project.

http://topersbbs.dtdns.net
telnet://topersbbs.dtdns.net





Quote:
Does C++ support Random access files too. I have done programing in pascal. I have all ways like that option.

I see. I never used pascal myself.
I'm not 100% sure I know what random access is but I think C++ has it.
Basically you can save anything anywhere in a file. No need to use records or IDs or anything like that. You decide how to organize data in the files.

Quote:
Look, If theres any thing I can do for you. Let me know. I have a web site and run a BBS too. I guess thats why I want to learn C++. To Replace the BBS software I'm running now. With my Own project.

Thanks mate, and good luck with the project :D
Quote:Original post by pulpfist
Quote:
Does C++ support Random access files too. I have done programing in pascal. I have all ways like that option.

I see. I never used pascal myself.
I'm not 100% sure I know what random access is but I think C++ has it.
Basically you can save anything anywhere in a file. No need to use records or IDs or anything like that. You decide how to organize data in the files.

Quote:
Look, If theres any thing I can do for you. Let me know. I have a web site and run a BBS too. I guess thats why I want to learn C++. To Replace the BBS software I'm running now. With my Own project.

Thanks mate, and good luck with the project :D


Your welcome and Thanks again!!

This topic is closed to new replies.

Advertisement