What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Saveing in C++

Pages: (2): « First « 1 [ 2 ] Last »
Saveing in C++
Author: Message:
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
RE: Saveing in C++
quote:
Originally posted by DJeX
Now I want to save the name's the user types in, the numbers in the edit boxes, the color of the edit boxes, the money amount at the top and the starting date at the top. Then also have it reload the exact same way through the settings file I saved all of it to.
quote:
Originally posted by Choli
and save into a file (or files) the data that the program manages: what the programs works with (user's data, documments, etc...).
you're right. You have to save all that data into a file.

(and note that you are not saving everithing of your program, you are not saving the whole status of the execution of the program, ie: you aren't saving which control has the focus, the position and size of the window, etc..... (you just don't need to) That's why I said i think you didn't want to save _all_ about the program)

This post was edited on 01-03-2005 at 10:28 PM by Choli.
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
01-03-2005 10:27 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Saveing in C++
quote:
Originally posted by DJeX
^ But it don't write the color of the box it writes a number like -256438

Well, that IS the colornumber though; a color is nothing more then a number...

A colornumber can be written in roughly two ways: signed and unsigned. -256438 is obviously a signed number (it can have a negative sign or a postive sign, while an unsigned number is always positive)

First, what is a color:

A color is made out of different components. The most known is Red Green and Blue. Each of those values can be from 0 to 255. So to represent all these 3 values in 1 number you simply add them together in a binary way: you "concatenate" the Blue value to the Green value which you "concatenate" to the Red value...

In hexadecimal it looks must simplier to explain: a RGB color is a number between 0 and FFFFFF.

the first FF is the Red value, the second FF is the Green value and the third FF is the Blue value (exactly the same as with HTML colorcodes :D) But together they form the hexadecimal number FFFFFF (being absolutely white). Now, when you convert this number to a decimal format you'll get: 16777215 because this comes from R * 2^0 + G * 2^8 + B * 2^16. So an RGB color uses a maximum of 24bits.

Though, the actual color used by windows consists of 4 individual values. so instead of a maximum of FFFFFF (hexadecimal) you can have FFFFFFFF (hexadecimal), or a maximum of 32bits. But the principle is just the same of course...

Signed/Unsigned:

To store numbers, the computer needs some memory locations. But of course using to much memory space isn't very efficient. That is why you have certain types of numbers. eg, a "byte" uses 1 byte, meaning you can use a number from 0 to 255. a "word" uses 2 bytes (the numbers 0 to 65535), a "double word" uses 4 bytes (the numbers 0 to 2^32-1), etc...

These are all positive numbers of course. So the PC needs to have a system where you can store negative numbers as well. This is where the signed/unsigned system comes into place.

With signed numbers you need to offer 1 bit up for the state of the sign. This leaves one bit less for the actually number:
If you take the space of 2 bytes (a "word"), you can have the number from 0 to 65535 (16bits), thus this will always be positive. Now, offer up 1 bit for the sign and you'll be left with only 15bits for the actual number, so now the number can go from -32767 to +32767 (but still there are 65536 possible numbers of course, just as before as it still uses 16bits in total)

So there you have it, the difference between a signed number and an unsigned number. In most programming languages, the signed number system is used by default.

Though, you can easly convert one into the other. eg: to convert a number in the range -32767 to +32767 (thus 16bit) to the range 0 to 65535, you add 32767 to the signed number: -32767 + 32767 (signed range) = 0 (unsigned range)

To conclude:

The same happens with that number you got; it is a 32bits number, signed.
You know that an unsigned 32bits number goes from 0 to 2^32-1, thus from 0 to 4294967295.
(^32 because there are 32bits to be used. And -1 to compensate for the number 0)
So, a signed 32bits number goes from -2^31+1 to +2^31-1, thus from -2147483647 to +2147483647
(^31 instead of ^32 because there is 1 bit used for the sign. And +1/-1 to compensate for the number 0)

So to get your unsigned 32bit number (the true raw colornumber) you must add 2^31+1 to that number:
-256438 + 2^31+1 =
-256438 + 2147483649 =
2147227211

To work with it:

Now, instead of storing the number as a signed number and then calculate the unsigned number from it when you read it again, you could also store it directly as a unsigned number of course. There are functions for that in each programming language, thus including C++

Also, some functions do accept a signed number and will correctly interpret/convert it to the correct value automatically, so you don't need to do anything at all. This can depend on the programming language and/or the type of function you use the number for.



Hope I made some sense... :p

This post was edited on 01-03-2005 at 11:14 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
01-03-2005 11:11 PM
Profile PM Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
RE: Saveing in C++
quote:
Originally posted by CookieRevised
Though, the actual color used by windows consists of 4 individual values. so instead of a maximum of FFFFFF (hexadecimal) you can have FFFFFFFF (hexadecimal), or a maximum of 32bits. But the principle is just the same of course...
the 8 extra bits are used for transparency (alpha channel) so at the end you still have 24 bits.
quote:
Originally posted by CookieRevised
go from -32767 to +32767 [...] So, a signed 32bits number goes from -2^31+1 to +2^31-1, thus from -2147483647 to +2147483647
actually signed numbers stored with n bits go from -2^(n-1) to 2^(n-1) - 1, ie: from -32768 to 32767 and from -2147483648 to 2147483647 for 16 and 32 bits ;)
quote:
Originally posted by CookieRevised
Now, instead of storing the number as a signed number and then calculate the unsigned number from it when you read it again, you could also store it directly as a unsigned number of course. There are functions for that in each programming language, thus including C++
I'd use that signed (and maybe negative) number to store the color and wouldn't change/convert it. You don't have to worry about what number it saves, you just know that the same that saves you can read it later and will be a valid number that represents a color (or whatever other thing you want to save).,
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
01-03-2005 11:39 PM
Profile PM Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: Saveing in C++
Ok I understand how it gets the number now. Thanks.

But now how do I call that number back into the Color propertie of my edit box.

I used this to save the Color number:

code:
TIniFile *StartUp = new TIniFile("IValues.ini");

StartUp->WriteString("CtlValues",  "txtColor",     Edit1->Color);

delete StartUp;

I tried to load it in with this but I get debug error:

code:
TIniFile *StartUp = new TIniFile("IValues.ini");

Edit1->Color  = StartUp->ReadString("CtlValues",  "txtColor", "");

delete StartUp;

Debug Errors:

quote:
[C++ Warning] save.cpp(30): W8018 Assigning AnsiString to TColor
[C++ Error] save.cpp(30): E2034 Cannot convert 'AnsiString' to 'TColor'

So it looks like to me that the Edit1->Color can't convert the Color number (AnsiString) to Edit1's Color propertie.

How would I get this to work?


*Sorry for all the questions. You all have been a big help. I'm new to this so don't mind me. :)

This post was edited on 01-04-2005 at 01:08 AM by DJeX.
[Image: top.gif]
01-04-2005 01:07 AM
Profile PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Saveing in C++
You need a function that converts from AnsiString to TColor. Look around at MSDN to see what you can find.
[Image: spartaafk.png]
01-04-2005 05:56 PM
Profile PM Web Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On