Board index » cppbuilder » TTrackBar woes, BCB6

TTrackBar woes, BCB6


2005-10-28 05:22:13 AM
cppbuilder56
I've got a TTrackBar that I need to assign values to based on engine
parameters. The TTrackBar's values of Maximum, Minimum, Frequency, and
Increment are all non-negative integers.
These are engine parameters I need to display on the TTrackBar are:
Pressure:
Maximum = 251,
Minimum = 0, and
Increment = 0.00390625
Temperature:
Maximum = 1735,
Minimum = -273, and
Increment = 0.03125
RPM:
Maximum = 8031.87,
Minimum = 0, and
Increment = 0.12
Torque:
Maximum = 125,
Minimum = -125, and
Increment = 1
Flow Rate:
Maximum = 3212.75,
Minimum = 0, and
Increment = 0.05
Voltage:
Maximum = 3213,
Minimum = 0, and
Increment = 0.05
Notice the engine parameters can be negative and fractional, which is where
the difficulty comes in.
I started by multiplying everything by 1000 to get into whole numbers, but
BCB6's Help says TTrackBar only accepts Integers (-32,767 to 32,767) for
Maximum and Minimum, so I was going over this with some of my Maximums.
Does anyone have a good routine that they wouldn't mind sharing?
Thanks in advance.
 
 

Re:TTrackBar woes, BCB6

Okay, I got it figured out (if anyone was interested or paying any
attention).
I'm posting my solution for critique by you Pros out there. I had to cut
out the proprietary routines, and I had to make the variables generic.
Also, I did not test the code after making these changes, so there could be
a typos...
/**********************************************************/
typedef struct _ENGINEPARAMS {
double res; // resolution
double max; // maximum
double min; // minimum
double ofs; // offset
double val; // value read
char pUnit[9]; // string for the Units display
int xER; // multipliER
} Tparams;
/**********************************************************/
Tparams pms[10000];
/**********************************************************/
/**********************************************************/
// To Set:
void __fastcall TForm1::ComboBox1_OnChange(TObject *Sender)
{
int i;
pms[i].ofs = pms[i].min;
if (pms[i].min < 0)
{
pms[i].max -= pms[i].min; // minus a negative = addition
pms[i].min = 0;
}
pms[i].xER = MaxInt / pms[i].max; // MaxInt = 32,767
pms[i].max *= pms[i].xER;
pms[i].res *= pms[i].xER;
TrackBar1->Frequency = pms[i].max / 10;
TrackBar1->Max = pms[i].max;
TrackBar1->LineSize = pms[i].res;
if (pms[i].res < 1)
{
TrackBar1->LineSize = pms[i].res + pms[i].res;
}
TrackBar1->Min = pms[i].min;
TrackBar1->Position = pms[i].val;
lblDescription->Caption = pms[i].desc;
str.printf("%5.2f %s", pms[i].ofs, pms[i].pUnit);
lblSpnMin->Caption = str;
double TrueValue;
TrueValue = (pms[i].max / pms[i].xER) + pms[i].ofs;
str.printf("%5.2f %s", TrueValue, pms[i].pUnit);
lblSpnMax->Caption = str;
}
/**********************************************************/
/**********************************************************/
// To Get:
void __fastcall TForm1::TrackBar1_OnChange(TObject *Sender)
{
pms[i].val = TrackBar1->Position;
double TrueValue = (pms[i].val / pms[i].xER) + pms[i].ofs;
AnsiString str;
str.printf("= %5.2f %s", TrueValue, pms[i].pUnit);
lblSpnNewValue->Caption = str;
}
/**********************************************************/
/**********************************************************/
// End Of Code
If anyone sees any part that is inefficient or could be otherwise done
better, please share your information!
Bonus question: Why did I elect to call the structure variables pms? :)
Happy Halloween!