Variable problem..

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 11
Reputation: lifei is an unknown quantity at this point 
Solved Threads: 0
lifei lifei is offline Offline
Newbie Poster

Variable problem..

 
0
  #1
Dec 7th, 2007
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?
  1. #include <Windows.h>
  2. #include <mmsystem.h>
  3. #pragma comment (lib,"winmm.lib")
  4.  
  5. int ,x,y;
  6. void CTestingDlg::OnPlay()
  7. {
  8. // TODO: Add your control notification handler code here
  9.  
  10. UpdateData(TRUE);
  11.  
  12. CString strFreq;
  13. CString strHL;
  14.  
  15. strFreq = m_strFreq;
  16. strHL = m_strHL;
  17.  
  18. strFreq.MakeUpper();
  19. strHL.MakeUpper();
  20.  
  21. if(strFreq=="x" && strHL=="y")
  22. PlaySound("x_y_2.wav",NULL,SND_FILENAME);
  23.  
  24. }
Last edited by Ancient Dragon; Dec 7th, 2007 at 7:33 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Variable problem..

 
0
  #2
Dec 7th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 11
Reputation: lifei is an unknown quantity at this point 
Solved Threads: 0
lifei lifei is offline Offline
Newbie Poster

Re: Variable problem..

 
0
  #3
Dec 7th, 2007
if it is necessary to used the variable, how should i write?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Variable problem..

 
0
  #4
Dec 7th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 18
Reputation: Aashath is an unknown quantity at this point 
Solved Threads: 5
Aashath's Avatar
Aashath Aashath is offline Offline
Newbie Poster

Re: Variable problem..

 
0
  #5
Dec 21st, 2007
Originally Posted by lifei View Post
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?
  1. #include <Windows.h>
  2. #include <mmsystem.h>
  3. #pragma comment (lib,"winmm.lib")
  4.  
  5. int ,x,y;
  6. void CTestingDlg::OnPlay()
  7. {
  8. // TODO: Add your control notification handler code here
  9.  
  10. UpdateData(TRUE);
  11.  
  12. CString strFreq;
  13. CString strHL;
  14.  
  15. strFreq = m_strFreq;
  16. strHL = m_strHL;
  17.  
  18. strFreq.MakeUpper();
  19. strHL.MakeUpper();
  20.  
  21. if(strFreq=="x" && strHL=="y")
  22. PlaySound("x_y_2.wav",NULL,SND_FILENAME);
  23.  
  24. }


a ) CString to int :

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


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 ....
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: Brent.tc is an unknown quantity at this point 
Solved Threads: 1
Brent.tc Brent.tc is offline Offline
Junior Poster in Training

Re: Variable problem..

 
0
  #6
Dec 21st, 2007
You have an extra comma (',') before the x... Is that your question, and is that even a problem?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1
Reputation: kunals is an unknown quantity at this point 
Solved Threads: 1
kunals kunals is offline Offline
Newbie Poster

Re: Variable problem..

 
0
  #7
Dec 23rd, 2007
I think the address befor var may be the reason
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Variable problem..

 
0
  #8
Dec 23rd, 2007
int ,x,y;
Delete the comma.

  1. strFreq.MakeUpper();
  2. strHL.MakeUpper();
  3.  
  4. if(strFreq=="x" && strHL=="y")
You made those strings into upper-case and then you compare it with lower-case string.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC