954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Variable problem..

Can i know what's wrong with the below source code? can i put the variable x, y like this? How it can't work?

#include <Windows.h>
#include <mmsystem.h>
#pragma comment (lib,"winmm.lib")

int ,x,y;
void CTestingDlg::OnPlay() 
{
	// TODO: Add your control notification handler code here
			
                UpdateData(TRUE);

	CString strFreq;
	CString strHL;

	strFreq = m_strFreq;
	strHL = m_strHL;
	
	strFreq.MakeUpper();
	strHL.MakeUpper();

	if(strFreq=="x" && strHL=="y")
		   PlaySound("x_y_2.wav",NULL,SND_FILENAME);

}
lifei
Newbie Poster
11 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

what makes you think you can compare integers and strings ? Ain't going to work. If the strings contain numeric digits then convert them to integers before doing the comparison.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

if it is necessary to used the variable, how should i write?

lifei
Newbie Poster
11 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

Are you new to c and c++ languages? You are asking a 1st semester student type of question. If you are then attempting to write an MFC program is way beyond your current level of knowledge. Get an introduction to computer programming book and start studying from page 1. Then in a year or so you will be ready for that MFC program.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Can i know what's wrong with the below source code? can i put the variable x, y like this? How it can't work?

#include <Windows.h>
#include <mmsystem.h>
#pragma comment (lib,"winmm.lib")

int ,x,y;
void CTestingDlg::OnPlay() 
{
	// TODO: Add your control notification handler code here
			
                UpdateData(TRUE);

	CString strFreq;
	CString strHL;

	strFreq = m_strFreq;
	strHL = m_strHL;
	
	strFreq.MakeUpper();
	strHL.MakeUpper();

	if(strFreq=="x" && strHL=="y")
		   PlaySound("x_y_2.wav",NULL,SND_FILENAME);

}

a )CString to int :

CString csNumber = "3";
int x;
x = atoi(csNumber); //defined in


b) int to CString

int x = 23;
CString csNumber;
csNumber.format("%d", x);

This will do .....

Make urself comfortable with basic C++ before moving into MFC ....

Aashath
Newbie Poster
18 posts since Dec 2007
Reputation Points: 11
Solved Threads: 5
 

You have an extra comma (',') before the x... Is that your question, and is that even a problem?

Brent.tc
Junior Poster in Training
90 posts since Oct 2006
Reputation Points: 10
Solved Threads: 1
 

I think the address befor var may be the reason

kunals
Newbie Poster
1 post since Dec 2007
Reputation Points: 10
Solved Threads: 1
 
int ,x,y;

Delete the comma.

strFreq.MakeUpper();
strHL.MakeUpper();

if(strFreq=="x" && strHL=="y")

You made those strings into upper-case and then you compare it with lower-case string.

invisal
Posting Pro
562 posts since Mar 2005
Reputation Points: 350
Solved Threads: 64
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You