CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    13

    Unhappy MultiLine Edit Box Problem

    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:

    Code:
    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

  2. #2
    Join Date
    Apr 2010
    Location
    Western WA, USA
    Posts
    59

    Re: MultiLine Edit Box Problem

    Quote Originally Posted by RJK View Post
    Code:
    char *cPrice1[1];
    ... snip ...
    cPrice1[0] = strtok(szPrice1, "\\");
    cPrice1[1] = strtok(NULL, "\\");
    ... snip ...
    I haven't analyzed your code logic, but I do see one error:
    you declare an array of one element. and then put two entries in it (index overflow).

    I'm guessing you meant: char *cPrice1[2];

  3. #3
    Join Date
    Apr 2010
    Posts
    13

    Re: MultiLine Edit Box Problem

    Hey thanks for the info, i thought that when you declared an array [1] would be [0] & [1].

    And if needed here is how i do my Multi Line Edit Box, if this error could be in there:

    Code:
    HWND hTxtOutput = CreateWindow("Edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOHSCROLL| ES_WANTRETURN | WS_VSCROLL, 10, 10, 400, 300, hwnd, (HMENU) IDC_OUTPUT, NULL, NULL);
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured