|
-
Aug 24th, 2001, 02:56 PM
#1
Thread Starter
Hyperactive Member
integers
Code:
int result;
int len = GetWindowTextLength(editwage);
if(len>0)
TCHAR *buf = new TCHAR[len + 1];
GetWindowText(editwage,buf,len+1);
MessageBox(NULL,buf,"hi",MB_OK);
int s = atoi(buf);
int len2 = GetWindowTextLength(edithrs);
if(len2>0)
TCHAR *buf2 = new TCHAR[len2 + 1];
GetWindowText(edithrs,buf,len2+1);
int b = atoi(buf2);
result = s * b;
char buffer[10];
char* sztext = itoa(result,buffer,10);
MessageBox(NULL,sztext,"testing",MB_OK);
return 0;
}
When I run this code or try to i get the error" buf, and buf2 undeclared identifiers". I declared them though. And then once I try and do the calculation on multiplying s and b I get 0 in the messagebox. I cannot figure out what is going on. Any help is greatly appreciated!!
Matt 
-
Aug 24th, 2001, 03:31 PM
#2
Member
Declare the variables outside the if blocks. Variable scope is causing the error.
-
Aug 24th, 2001, 04:41 PM
#3
If your if statement requires more than one statement in it, you need to enclose them in braces
Code:
if(len>0)
{
TCHAR *buf = new TCHAR[len + 1];
GetWindowText(editwage,buf,len+1);
MessageBox(NULL,buf,"hi",MB_OK);
int s = atoi(buf);
}
-
Aug 24th, 2001, 07:46 PM
#4
Thread Starter
Hyperactive Member
but will i be able to use the variable s outside of the braces, or in another set?
Matt 
-
Aug 24th, 2001, 08:06 PM
#5
Frenzied Member
I don't see your starting brace but if you declare the variable as global you will be able to use it everywhere. Global declaring is not recommended though!
-
Aug 25th, 2001, 04:55 PM
#6
Member
Code:
// wrong
if (1)
{
int i = 3;
}
cout << i; // variable not defined in this scope
// correct
int i;
if (1)
{
i = 3;
}
cout << i; // variable is defined in scope
-
Aug 26th, 2001, 02:34 PM
#7
Thread Starter
Hyperactive Member
finally got it thanks alot guys!
Matt 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|