Support Board
Date/Time: Fri, 29 Nov 2024 02:50:57 +0000
Post From: canceled stop order continues to have status SCT_OSC_OPEN
[2023-03-16 23:03:27] |
ondafringe - Posts: 286 |
A few things to consider: 1. Whenever you declare a variable, you should always initialize it (set it to some default value), which you did in your second code snippet. 2. stopOrderID is in scope for the entirety of your code snippet. It will not be destroyed unless it goes out of scope (maybe in some other part of your code). Revisit the examples in Post #10, above. 3. Your if-statement is incomplete, which *may* be part of your earlier problem. If you *only* want this line (StopOrderID = Data.InternalOrderID) to execute based on the if-statement condition being true, then you need to complete the if-statement, as so: if ((StatusCode == SCT_OSC_OPEN) && (TypeAsInt == 3)) { StopOrderID = Data.InternalOrderID; } Unless I'm missing something, based on your code, your if-statement condition is being ignored, so stopOrderID is being updated on every pass, and will retain its value unless it goes out of scope, or is explicitly reset. And you are explicitly resetting it to zero in your second code snippet; or, more accurately, you are redeclaring the variable and giving it a default value of zero. Edit: After rereading your last post, I wasn't certain what you meant by "base level." I now think you are referring to the main part of the study where your primary code is encompassed within: SCSFExport scsf_XXXXXXXXXX(SCStudyInterfaceRef sc) { } If that is the case, then from what I *think* I know is, variables declared within that structure are destroyed after leaving the end of that structure, and then recreated upon being redeclared once the declaration code is re-executed on subsequent passes through that structure. Having said that, if you try to access that variable prior to redeclaration, I'm guessing you will probably see garbage (or something akin to garbage) because that variable would no longer exist until it's been redeclared. So your StopOrderID *should* be destroyed as it goes out of scope, and then gets recreated/destroyed again and again upon subsequent passes, which is what's happening... because if it wasn't destroyed, redeclaring a local variable that is still in scope would probably throw a compile error, which apparently didn't happen. And declaring StopOrderID without initializing it, as you first did, would probably result in StopOrderID containing garbage (or something akin to garbage) until it had been assigned a value. Now, I'm no code guru, not even close, but that's my take. Date Time Of Last Edit: 2023-03-17 05:12:45
|