Getting data in to C++ from excel, any help would be greatly appreciated - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 54

Thread: Getting data in to C++ from excel, any help would be greatly appreciated

  1. #16
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,047

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Unless you have conditional breakpoints set, a debug build shouldn't slow you down a whole lot.

  2. #17
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by Surreall View Post
    Sounds fair enough. With the q and c if you look at my little 3x3 matrix above. I compare column1(ie q) with the second and third column (ie c). I then compare column 2 (q) with the first and third column (ie c) and lastely compare column3 (q) with the first and second column(c).
    Forget about C++ for a moment and think about a generic approach. That's why I asked about the magic numbers -- those numbers should be data that drives the generic approach, not hardcoded.

    Too many times, persons write the code so that it becomes inflexible, just to get something working. I never take that approach. Right now, you are using 2, 15, 45, etc. But what if you get the same setup, but the columns are now 3, 13, and 27? Are you going to continually change the code to accommodate those new numbers?

    For example, you have a matrix with n columns, and for each iteration up to n, you want to compare columns that are not n.
    Code:
    int currentColumn = someValue;
    for ( int i = 0; i < numTotalColumnsInArray; ++i )
    {
        if ( i == currentColumn )
           continue;
        if ( CompareMatrix(currentColumn, i) == whatever )
        {
            // do whatever
        }
    }
    I whittled down your explanation to those few lines.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; January 31st, 2013 at 12:24 PM.

  3. #18
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by GCDEF View Post
    Unless you have conditional breakpoints set, a debug build shouldn't slow you down a whole lot.
    I don't know about gcc, but any usage of STL in Visual C++ is a huge bottleneck in debug builds, due to the iterator checking.

    Regards,

    Paul McKenzie

  4. #19
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    I have very very few debugging options, most are greyed out. Those that are on in settings are:

    - Autobuild project if it is not up to date
    - When stopping, autoswitch to first frame with valid source info
    - enable watch scripts
    - catch c++ expressions

    None others are ticked

  5. #20
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Code:
    int currentColumn = someValue;
    for ( int i = 0; i < numTotalColumnsInArray; ++i )
    {
        if ( i == currentColumn )
           continue;
        if ( CompareMatrix(currentColumn, i) == whatever )
        {
            // do whatever
        }
    }
    Yeah thats pretty much it, should i change the two for loops (q and c) for something similar to this?

    As for the 15's and 30's etc, i cannot forsee needing to change them. Same with the 1's or 0's or 2's or headers. At least not for the next 6 months.
    Last edited by Surreall; January 31st, 2013 at 01:20 PM.

  6. #21
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by Surreall View Post
    I have very very few debugging options, most are greyed out. Those that are on in settings are:

    - Autobuild project if it is not up to date
    - When stopping, autoswitch to first frame with valid source info
    - enable watch scripts
    - catch c++ expressions

    None others are ticked
    The options you want are ones that control optimizations, not debugging options. You want to turn off debugging and turn on optimizations if you want to know exactly how your program performs.

    The gcc compiler itself has numerous optimization settings -- maybe there is an entry in the IDE you're using to enter these commands if those options do not show up in the IDE.

    Remember that CodeBlocks is not the compiler, gcc is the compiler If you want to know the gcc options, go to the command line and type (I believe)
    gcc --help
    Or something similar to that. The gcc.exe program has to be in your system path (or you CD to the directory that contains the executable).

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; January 31st, 2013 at 01:22 PM.

  7. #22
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by Surreall View Post
    Code:
    int currentColumn = someValue;
    for ( int i = 0; i < numTotalColumnsInArray; ++i )
    {
        if ( i == currentColumn )
           continue;
        if ( CompareMatrix(currentColumn, i) == whatever )
        {
            // do whatever
        }
    }
    Yeah thats pretty much it, should i change the two for loops (q and c) for something similar to this?
    If that fits the description, then you can use the same pattern above.
    As for the 15's and 30's etc, i cannot forsee needing to change them.
    Always think of future changes now, not when it comes time when things do change.

    What inevitably happens is that you now build a mountain of code driven by hard-coded values, and then it becomes very difficult, if not near impossible to salvage anything when requirements do change. Or worse, you do the old "I'll change this 2 to a 10, and this 4 to a 7, etc." and now

    1) The old program is gone, unless you saved a backup.
    2) You've risked breaking the code by changing the source, hoping that you got every constant that needs changing.
    3) You have to rebuild each and every time a requirement changes, instead of just changing the data that drives the program.

    Regards,

    Paul McKenzie

  8. #23
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    In the global compiler settings, these are the ones that seem to do with optimising. If that is what you mean?

    -optimize generated code (for speed) [-O]
    -optimize more (for speed) [-O1]
    -optimize even more (for speed) [-O2]
    -Optimize fully (for speed) [-O3]
    -Optimize generate code (for size) [-Os]
    -Expensive optimizations [-fexpensive-optimizations]
    -strip all symbols from binary (minimizes size) [-s]


    There are also a shed load of warning options, which i presume i don't need, and some "have g++ follow language standards"

  9. #24
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Good point, for example if i could get the currently 6 mins down to say under 30 seconds i might be tempted to use more data that is available, and those 15's which are minutes, could become singles upto 60. Although that would mean completely changing the code anyway. But i get what you mean, it would be painfully to debug afterwards if there was a change. It is very annoying when code doesnt work, and you have no idea why, just to find in a couple of hours later a little number you forgot about

  10. #25
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by 2kaud View Post
    Code to help with exporting
    Thankyou 2kaud i will give that ago tomorrow, and get back to you with the results

    Another thought i had while out running, with this part of the code:

    Code:
    if (dataarray[jRows + indicator1position][c]==indicator1value && \
    dataarray[jRows + indicator2position][c]==indicator2value && \
    dataarray[jRows + trade1position][q]==trade1value && \
    dataarray[jRows + trade2position][q]==trade2value)
      {
    I am probably wrong, but as this part is iterated almost every time. What about splitting it up. So it only does the first check, and if false it doesnt do the other ones, and if that is true then do the second check and so on to the last check?
    Last edited by Surreall; January 31st, 2013 at 01:38 PM.

  11. #26
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    In c++ with a multi condition statement, the conditions are only evaluated left to right as needed to correctly obtain the result. So in the case of &&, the left test if evaluted first. If it is false then no more evaluations are done as the result must be false. Only if the test is true is the next condition evaluated. This repeats until either a false is found with && (or true for ||) or the whole expression is evaluated. Splitting it up will make no difference to execution speed. However the order as stated from left to right might. If one condition is more likely to be false than others then this condition should be the first one so that if it is false then the others aren't evaluted.

  12. #27
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Excellent thankyou for the info, i will go through and see which is false more often. That should help a bit at least

  13. #28
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    I also note in your code that you are not pre-reserving space for the vectors. If a vector does not have enough memory to store an extra element then it will re-allocate memory and copy existing elements into the new space when the extra element is added. If a vector has many elements added then this will take time. To avoid this reallocation initial space can be reserved. From my previous example, if it is expected that the result vector has, say, 5000 elements then memory for these can be pre-allocated

    Code:
    vector<results> resultsarray;
    resultsarray.reserve(5000);
    This means that memory re-allocation will now only occur if more than 5000 elements are stored in the vector.

  14. #29
    Join Date
    Jan 2013
    Posts
    27

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by 2kaud View Post
    I also note in your code that you are not pre-reserving space for the vectors. If a vector does not have enough memory to store an extra element then it will re-allocate memory and copy existing elements into the new space when the extra element is added. If a vector has many elements added then this will take time. To avoid this reallocation initial space can be reserved. From my previous example, if it is expected that the result vector has, say, 5000 elements then memory for these can be pre-allocated

    Code:
    vector<results> resultsarray;
    resultsarray.reserve(5000);
    This means that memory re-allocation will now only occur if more than 5000 elements are stored in the vector.
    Your previous code for export to csv file worked a treat, ty very much.

    I am getting a few bizarre results though:

    With this part of the code:
    Code:
                    float t = ( y / z );
                    if (y==0){y = 1;}
                    if (z==0){z = 1;}
                    if ( t > 3 && y > 20 )
    When i set t > 2 and y > 10, it works fine. And i see i get results where t is also > 3 and y > 20.

    So i reset it to t > 3 & y > 20, to reduce the number of results. As i know there are results with these. But the programme closes without finishing. I presume cause results is empty. So it fails.

    Any suggestions?

    Rgds

    Surreall

  15. #30
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Getting data in to C++ from excel, any help would be greatly appreciated

    Quote Originally Posted by Surreall View Post
    I am getting a few bizarre results though:

    With this part of the code:
    Code:
                    float t = ( y / z );
                    if (y==0){y = 1;}
                    if (z==0){z = 1;}
                    if ( t > 3 && y > 20 )
    I wonder why you check the value of z to be zero after if has been used in
    Code:
                    float t = ( y / z );
    Why not before it?

    Quote Originally Posted by Surreall View Post
    ... But the programme closes without finishing. I presume cause results is empty. So it fails.

    Any suggestions?
    Debug it and you will see!
    Victor Nijegorodov

Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center