RJK
May 29th, 2010, 09:24 AM
I am creating a betting program, basically what it does it it calculates the bet and outputs it into a Multi Line Edit Box, but it only allows a certain amount of characters:
char szNum[20], szBet[20], szPrice1[4], szTotal[20], szReturns[20], szOutput[MAX_PATH];
char *cPrice1[1];
stringstream strBet, strPrice1, strOutput;
int nAdd;
float fReturns, fTot, fRet;
GetWindowText(GetDlgItem(hwnd, IDC_STAKE), szNum, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDD_BETDD), szBet, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_PRICE1), szPrice1, MAX_PATH);
strBet.str(szBet);
if (strlen(szNum) == 0)
{
MessageBox(NULL, "Please Enter a Stake", "Error", MB_OK | MB_ICONWARNING);
} else if (strlen(szBet) == 0) {
MessageBox(NULL, "You have not selected a Bet Type", "Error", MB_OK | MB_ICONWARNING);
} else if (strBet.str() == "Single"){
cPrice1[0] = strtok(szPrice1, "\\");
cPrice1[1] = strtok(NULL, "\\");
fTot = atof(szNum) / atof(cPrice1[1]);
nAdd = atoi(cPrice1[0]) + atoi(cPrice1[1]);
fReturns = fTot * nAdd;
GetWindowText(GetDlgItem(hwnd, IDC_PRICE1), szPrice1, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_OUTPUT), szOutput, MAX_PATH);
strOutput.str(szOutput);
for (int i = 0; i < strlen(szNum); i++)
{
if (!isdigit(szNum[i])) {
MessageBox(NULL, "Invalid Character, Returns = £0", "Error", MB_OK | MB_ICONWARNING);
fReturns = 0;
SetWindowText(GetDlgItem(hwnd, IDC_STAKE), "Error");
i = strlen(szNum);
}
}
strBet << strOutput.str() << "Single Bet: £" << szNum << " @ " << szPrice1 << " Returns: £" << fReturns << "\r\n";
SetWindowText(GetDlgItem(hwnd, IDC_OUTPUT), strBet.str().c_str());
GetWindowText(GetDlgItem(hwnd, IDC_RETURNS), szReturns, MAX_PATH);
fRet = atof(szReturns) + fReturns;
sprintf(szReturns, "%.2f", fRet);
SetWindowText(GetDlgItem(hwnd, IDC_RETURNS), szReturns);
}
This is the code when the user clicks the 'Calculate Bet' button.
Note: I am learning WinAPI so if there are problems or any better ways of doing things that i have done, please feel free to say.
If i click the button loads of times (for testing) it only allows a certain amount of characters:
http://img444.imageshack.us/img444/8153/problemx.png
You can see that once it gets to a certain line it just adds onto it and i cant go down any further.
Can anyone provide a solution.
Thanks in advance,
RJK
char szNum[20], szBet[20], szPrice1[4], szTotal[20], szReturns[20], szOutput[MAX_PATH];
char *cPrice1[1];
stringstream strBet, strPrice1, strOutput;
int nAdd;
float fReturns, fTot, fRet;
GetWindowText(GetDlgItem(hwnd, IDC_STAKE), szNum, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDD_BETDD), szBet, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_PRICE1), szPrice1, MAX_PATH);
strBet.str(szBet);
if (strlen(szNum) == 0)
{
MessageBox(NULL, "Please Enter a Stake", "Error", MB_OK | MB_ICONWARNING);
} else if (strlen(szBet) == 0) {
MessageBox(NULL, "You have not selected a Bet Type", "Error", MB_OK | MB_ICONWARNING);
} else if (strBet.str() == "Single"){
cPrice1[0] = strtok(szPrice1, "\\");
cPrice1[1] = strtok(NULL, "\\");
fTot = atof(szNum) / atof(cPrice1[1]);
nAdd = atoi(cPrice1[0]) + atoi(cPrice1[1]);
fReturns = fTot * nAdd;
GetWindowText(GetDlgItem(hwnd, IDC_PRICE1), szPrice1, MAX_PATH);
GetWindowText(GetDlgItem(hwnd, IDC_OUTPUT), szOutput, MAX_PATH);
strOutput.str(szOutput);
for (int i = 0; i < strlen(szNum); i++)
{
if (!isdigit(szNum[i])) {
MessageBox(NULL, "Invalid Character, Returns = £0", "Error", MB_OK | MB_ICONWARNING);
fReturns = 0;
SetWindowText(GetDlgItem(hwnd, IDC_STAKE), "Error");
i = strlen(szNum);
}
}
strBet << strOutput.str() << "Single Bet: £" << szNum << " @ " << szPrice1 << " Returns: £" << fReturns << "\r\n";
SetWindowText(GetDlgItem(hwnd, IDC_OUTPUT), strBet.str().c_str());
GetWindowText(GetDlgItem(hwnd, IDC_RETURNS), szReturns, MAX_PATH);
fRet = atof(szReturns) + fReturns;
sprintf(szReturns, "%.2f", fRet);
SetWindowText(GetDlgItem(hwnd, IDC_RETURNS), szReturns);
}
This is the code when the user clicks the 'Calculate Bet' button.
Note: I am learning WinAPI so if there are problems or any better ways of doing things that i have done, please feel free to say.
If i click the button loads of times (for testing) it only allows a certain amount of characters:
http://img444.imageshack.us/img444/8153/problemx.png
You can see that once it gets to a certain line it just adds onto it and i cant go down any further.
Can anyone provide a solution.
Thanks in advance,
RJK