|
Rounding error.
Floating-point numbers cannot be stored as the exact equivalent of their decimal representation, unless they all happen to be powers of two (2, 4, .125, etc.). So you should never check for strict equality when dealing with float /double values.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0! | RightClick-Encrypt
"Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."
-- Paul Watson, Linux Zombie
|
|
|
|
|
Thanks but im not sure I understand completely. Would you expect "true" or "false" from the following code? It prints true when i run it.
double d1 = 5; //not a power of 2
double d2 = 2;
if( (d2 * 5.0 / 2.0) == d1)
printf("true");
else
printf("false");
|
|
|
|
|
You are using whole numbers. Try with fractions
double d1 = 1;
double d2 = 3;
double d3 = d1 / d2;
if (d3 == 0.333)
printf ("true");
else
printf ("false); No matter what number you use, you will never get true.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
|
Hi there,
I'm relatively new to the C++ language. Recently I started with a database application in Visual C++6.
Here is my question:
After loading a couple of (lest's say four) Edit boxes from an MS Access database through the MFC ODBC, I would like to calculate the value of some of the boxes and have the sum in a fifth Edit box.
The database consist of both integer and floating numbers.
I use the GetFieldValue to copy database values into a variable using the CString class.
How do I get the variables recognized as numbers?
This is easy to do in VB6 but how is it done in Visual C++6. There must be a way!
I would really appreciate all the help I can get.
Thanks in advance
Lars
|
|
|
|
|
atof()<br />
atoi()<br />
_atoi64()<br />
atol()<br />
atold()<br />
strtod()<br />
StrToInt()<br />
StrToIntEx()<br />
strtol()<br />
strtoul()
Take your pick
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I am a Visual C++ newbie (I worked with Borland Delphi a long time so I know something... although not what I need now).
I have to write a file encoder. In VC++ 6
Everything is set, I began a new project with MFC AppWizard, I selected dialog-based and now I have a dilemma:
How do I show up an "Open file" dialog type window??! and a save one too...
I would like if possible to be able to change the file filter and/or caption (I am developping it in another language)
Like in Notepad when you hit CTRL-O or File->Open. I don't necesarily need it Win2000/XP style but I HOPE THERE IS A FUNCTION IN THE WIN SDK.
In delphi it was so simple.Just drop a OpenFileDialog control on the main form and say: "Dialog1.Execute();"
Visual C++ is certainly no RAD for me...
Thanks in advance!
|
|
|
|
|
Sure there is a function in the windows sdk, it's called GetOpenFileName
Just fill in the OPENFILENAME struct an call the function.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you very much!
It helped
Now I also used GetSaveFileName !
|
|
|
|
|
I've created a dialog with nothing special in it. I don't know why, but I continue to get the following errors:
error C2065: 'IDD_SORU' : undeclared identifier
error C2057: expected constant expression
All for the following line of code, which I did not write:
/ Dialog Data
enum { IDD = IDD_SORU };
</code>
I have rebuilt everything, even deleted the dialog and remade it. Any ideas?
If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
Looks like IDD_SORU is not declared. This should be in your resource header file, its probably called resource.h
Visula Studio should have added a #define tot his file for IDD_CORU when you created the dialog. Its not unusual for Visual Studio to get confused with these things.
Open your resource.h file
At the bottom there is a line like the following
#define _APS_NEXT_RESOURCE_VALUE 348
Add a #define for IDD_SORU to the resource.h file
use the number from the _APS_NEXT_RESOURCE_VALUE line and increment _APS_NEXT_RESOURCE_VALUE
so in this example you would add the following line
#define IDD_SORU 348
and modify this line
#define _APS_NEXT_RESOURCE_VALUE 349
Hope that helps
|
|
|
|
|
Thanks for the help!
It seems that it is already defined in the resource.h file. It is defined as 132 and the _APS_NEXT_RESOURCE_VALUE is defined as 133. Should I simply delete the entire dialog and try again?
If you have a problem with my spelling, just remember that's not my fault. I (as well as everyone else who learned to spell after 1976) blame it on Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
That will probably work.
It could be a problem with the pre-compiled headers. Try a rebuild all. Also check that the resource.h is included in the dialog header file
|
|
|
|
|
Platform: Win2k / Visual Studio 6.0, all service packs
I'm writing an AppWizard, using the builtin appwizard generator and I have problems loading / using bitmaps in my dialogs.
I'm importing a bmp and insert them into one of my dialog resources (IDD_CUSTOM1) as a picture control, using the resource / dialog editor.
The picture appears in the resource editor, but does not appear when running it through VS6.0, there are no error messages.
Anyone seen this problem and know the solution?
- Jo
|
|
|
|
|
Hello,
When the selection of my tree control changes I would like to get the item icon index, I have this code:
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;<br />
int iImage=pNMTreeView->itemNew.iImage;
However, the value of iImage is something like 1242756 or -86040328 (if I use a more indirect method). In fact, the entire NVITEM structure seems to have wrong values (the pszText member has jibberish).
I've also tried this:
TVITEM item;<br />
item.hItem=m_TreeCtrlName.GetSelectedItem();<br />
int iImage=item.iImage
Which will return a different, incorrect value. The GetImageCount from the TreeCtrl's ImageList returns the correct value though. Any idea of what I'm doing wrong?
Thanks,
Aaron Stubbendieck
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Aaron Stubbendieck wrote:
When the selection of my tree control changes I would like to get the item icon index, I have this code:
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
int iImage=pNMTreeView->itemNew.iImage;
However, the value of iImage is something like 1242756 or -86040328 (if I use a more indirect method). In fact, the entire NVITEM structure seems to have wrong values (the pszText member has jibberish).
According to MSDN, only the mask, hItem, state, and lParam members of TVITEM structure are valid. You should check the mask bits to ensure the member you want is valid before you try to accesss it.
That said, you can use CTreeCtrl::GetItemImage() to get the image from the hItem member of the TVITEM structure.
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
TVITEM tvnew = pNMTreeView->itemNew;
int iImage = 0;
if (tvnew.mask & TVIF_HANDLE == TVIF_HANDLE)
{
int selimage;
GetItemImage(tvnew.hItem, iImage, selimage);
}
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Ah, thank you for pointing out that those members weren't valid, and I'm not sure how I over looked GetItemImage. Its working perfectly now.
modified 12-Jul-20 21:01pm.
|
|
|
|
|
how to add two different projects .in a single project and to call each other or how to call functions of each other
|
|
|
|
|
U can just import the corresponding files which has ur functions.
Shanmuga Sundar.V
|
|
|
|
|
Hello!
I've created a MFC dialog-based project without context-sensitive help. When I now press F1 a window pops up telling me that the help file hasn't been found.
How can I disable this feature?
I've searched MSDN and found that the function CWinApp::OnHelp is called... Should I override this function?
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Dominik Reichl wrote:
CWinApp::OnHelp is called... Should I override this function
Close, but not quite. What I do is simply comment out the the line in your application class' message map that calls CWinApp::OnHelp
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I've created a dialog-based project without context-sensitive help. That line doesn't exist in my message map, neither in the CWinApp class nor in the main dialog class.
Now?
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
Oh oh... it actually does exist... I've overseen it
Sorry, problem solved, thanks!
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I have (probably) a very naive question, but I haven't done this before !!
I have just downloaded the Progress Dialog project from this website. However, having unzipped the package, I cannot find any project workspace file and therefore can't build the project. The only clue seems to be in the .dsp file which contains the following text:
# Microsoft Developer Studio Project File - Name="IProgDlg" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=IProgDlg - Win32 Debug Unicode
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "IProgDlg.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "IProgDlg.mak" CFG="IProgDlg - Win32 Debug Unicode"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "IProgDlg - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "IProgDlg - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE "IProgDlg - Win32 Release Unicode" (based on "Win32 (x86) Application")
!MESSAGE "IProgDlg - Win32 Debug Unicode" (based on "Win32 (x86) Application")
!MESSAGE
I don't understand where I find the "Export Makefile" command that it mentions.
Also, I am only running VC++ Ver. 4.0 and I see that Version 6.00 is mentioned above - is this a problem ??
Any help would be greatly appreciated
Doug
|
|
|
|
|