Consulting

Results 1 to 9 of 9

Thread: Solved: Visual C++: Loops Question

  1. #1
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location

    Solved: Visual C++: Loops Question

    When I try to debug the code below I get the following error message:
    "error C2061: syntax error : identifier 'intCounter'"
    The error points to the line of code with the while keyword.

    What am I doing wrong with this do...while loop structure?

    [vba]
    private
    : System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
    Int16 intCounter = 0;
    Int16 intArray[] = {1,2,3,4,5};
    do
    {
    String^ strMsg = gcnew String(intArray[intCounter].ToString());
    MessageBox::Show(strMsg);
    }while intCounter < 5;

    }
    [/vba]
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    As stated in an earlier post my C++ is very rusty. Are you incrementing the intCounter?
    [VBA]while (intCounter < 5);[/VBA]

  3. #3
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Are you incrementing the intCounter?
    Yes, I am... I just neglected to include it.

    I can't believe the solution was as simple as encasing the parameter of the 'while' keyword in parentheses!

    Here's the working code:

    [VBA]
    private
    : System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
    Int16 intCounter = 0;
    Int16 intArray[] = {1,2,3,4,5};
    do
    {
    String^ strMsg =
    gcnew String(intArray[intCounter].ToString());
    MessageBox::Show(strMsg);
    intCounter ++;
    }
    while (intCounter < 5);
    }
    [/VBA]
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  4. #4
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by CreganTur
    ...I can't believe the solution was as simple as encasing the parameter of the 'while' keyword in parentheses!...
    Yeah, get used to that. C++ is not as flexible as VB/VBA. IF statements, method calls, and anything else where you think should have parenthesis, should have parenthesis.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  5. #5
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Yeah, get used to that. C++ is not as flexible as VB/VBA. IF statements, method calls, and anything else where you think should have parenthesis, should have parenthesis.
    Yeah, I'm finding this out the hard way. I dl'ed the C++ for Beginners book that Microsoft is hosting on MSDN, so I'm learning about the Visual C++ Command Line and CPP files. I just wish that they had the same intellisense as Visual C++
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  6. #6
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Can I ask why you are developing in VC++'s command prompt?

    I'm assuming you type in "edit newFile.cpp" and you create your code in there.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  7. #7
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    yes, I do. Then I use "cl /EHsc [filename].cpp" to compile it.

    I'm only doing this because the book I mentioned from MSDN is C++, not Visual C++, so all of its examples are .cpp files.

    I've got another book that is specifically for Visual C++, but I'm holding back on it until I get a better grasp of regular old C++
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  8. #8
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    I see. If it helps, you can program cpp files in Visual C++. Just open VC++ and choose new project --> win32 --> Windows Console App --> In the application settings be sure to select "Empty Project" --> Finish. Then Add new Item --> Code --> Cpp file.

    From there you can create C++ code (the visual part is basically reserved for userforms) that has a cpp file with the code in it. You can still compile the cpp file using the VC++ Command Line if you want, but at least you can create the code and have Intellisense to help you.

    Hope this helps!




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  9. #9
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    I do that already- write the code in Visual C++ and use the command line to compile. It just seems like the intellisense for CPP files isn't as robust as it is for UserForms.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

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