Login Page - Create Account

Support Board


Date/Time: Wed, 27 Nov 2024 10:32:38 +0000



Post From: Code help, using a string instead of a constant

[2023-08-27 13:37:30]
j4ytr4der_ - Posts: 938
I'm modifying some open source code (from https://gcuserstudies.github.io/) but have run into a problem I've been unable to figure out how to solve. I'm sure this should be ridiculously simple but I've been at this for days and can't figure it out.

There is some code that evaluates a formula. It works fine for a single iteration, but I want it to execute in a (manual) loop of all the available inputs. This is a problem because the original loop uses a constant (
const char*
) and so the loop can't modify it each time. I've tried using an SCString instead but then the value of the formula gets mangled and doesn't appear to execute properly.

In abbreviated form, here's the code that "works" in the loop of inputs, but the value of the constant never changes once it's set the first time.



  ParseAndSetFormula = sc.IsFullRecalculation;

  const char* Formula = sc.Input[InputIndex].GetString(); // Grab the formula for the chosen input

  double FormulaOutput = sc.EvaluateGivenAlertConditionFormulaAsDouble(BarIndex, ParseAndSetFormula, Formula); // Evaluate the formula

  sc.Subgraph[InputIndex][BarIndex] = (float)FormulaOutput; // Return the formula result in a subgraph



I've tried changing
const char* Formula
to
SCString Formula
but it doesn't work. I've also tried just using
char
rather than
const char
but that won't even compile.

I know slightly more than nothing about C++ so I'm fairly sure I'm probably missing something really simple/obvious to someone who knows what they're doing. Can anyone point me in the right direction here?