Saving location and data

G

Guest

I apologize if this is in the wrong discussion group. I have a C++ form
(VS2003) that includes a couple text boxes and a slider bar. Moving the
slider bar changes a picture that is displayed and some label elements and
the text boxes have an initial value of 0. When a value is typed into the
text boxes I want it to be saved based on the position of the slider bar. I
am assuming that I need to write that text to the array, but I am not sure if
that is right. I want it to save it when a Save button is pressed or the
slider position changes. Any help would be appreciated, Thanks
 
D

David Lowndes

I apologize if this is in the wrong discussion group. I have a C++ form
(VS2003) that includes a couple text boxes and a slider bar. Moving the
slider bar changes a picture that is displayed and some label elements and
the text boxes have an initial value of 0. When a value is typed into the
text boxes I want it to be saved based on the position of the slider bar. I
am assuming that I need to write that text to the array

What array?

Dave
 
G

Guest

Here is some sample code of the array
static CListOfTeams *Team[] = __gc new CListOfTeams*[22];
private: System::Void Form1_Load(System::Object * sender,
System::EventArgs * e)
{
Team[0] = new CListOfTeams;
Team[0]->Team = S"Cleveland Browns";
Team[0]->Week = S"Pre-Season Week 1";
I want to save it here //Team[0]->Score = 16;
//Team[0]->Allowed = 12;
Team[0]->TeamPic = S"8080146.jpg";
Team[0]->Sched = S"6:30pm August 11 at Cleveland";
//Team[0]->Wins = 16;
//Team[0]->Loss = 12;

Team[1] = new CListOfTeams;
Team[1]->Team = S"Miami Dolphins";
Team[1]->Week = S"Pre-Season Week 2";
//Team[1]->Score = 11;
//Team[1]->Allowed = 10;
Team[1]->TeamPic = S"8080155.jpg";
Team[1]->Sched = S"7:00pm August 16 at KC";
//Team[1]->Wins = 27;
//Team[1]->Loss = 22;
 
G

Guest

Here is some sample code of the array
static CListOfTeams *Team[] = __gc new CListOfTeams*[22];
private: System::Void Form1_Load(System::Object * sender,
System::EventArgs * e)
{
Team[0] = new CListOfTeams;
Team[0]->Team = S"Cleveland Browns";
Team[0]->Week = S"Pre-Season Week 1";
I want to save it here //Team[0]->Score = 16;
and here //Team[0]->Allowed = 12;
Team[0]->TeamPic = S"8080146.jpg";
Team[0]->Sched = S"6:30pm August 11 at Cleveland";


Team[1] = new CListOfTeams;
Team[1]->Team = S"Miami Dolphins";
Team[1]->Week = S"Pre-Season Week 2";
//Team[1]->Score = 11;
//Team[1]->Allowed = 10;
Team[1]->TeamPic = S"8080155.jpg";
Team[1]->Sched = S"7:00pm August 16 at KC";

private: System::Void trackBar1_Scroll(System::Object * sender,
System::EventArgs * e)
{
int CurPos = this->trackBar1->Value - 1;
this->lblTxtTeam->Text = this->Team[CurPos]->Team;
this->lblTxtWeek->Text = this->Team[CurPos]->Week;
this->txtScored->Text = this->Team[CurPos]->Score.ToString();
this->txtAllowed->Text = this->Team[CurPos]->Allowed.ToString();
this->lblSched->Text = this->Team[CurPos]->Sched;
this->pictureBox2->Image = Drawing::Image::FromFile(Team[CurPos]->TeamPic);
this->lblTtlAllowed->Text = this->Team[CurPos]->Wins.ToString();
this->lblTtlScored->Text = this->Team[CurPos]->Loss.ToString();
}

Hope this helps.
 
D

David Lowndes

Here is some sample code of the array

OK, so your slider position reflects the index to this array of items?

In essence you need to know (either read it from the slider control or
save it in a member variable) the current position (index) of the item
you're displaying, and in the appropriate events (save button press &
change of scroll position) copy the current values from the text
fields back to that item of the array.

Dave
 
G

Guest

Correct. The initial value of say position 2 is 0 & 0. If I change them to 14
& 12, the next time I return to position 2 the values should be 14 & 12. I'm
just not certain of how to do this. Still kinda new to C++.
Thanks
 
D

David Lowndes

Correct. The initial value of say position 2 is 0 & 0. If I change them to 14
& 12, the next time I return to position 2 the values should be 14 & 12. I'm
just not certain of how to do this. Still kinda new to C++.

Which aspect are you having a problem with though - it's not really a
C++ issue, is it?

For starters, you need to use the IDE to add an event handler for your
"Save" button click event and then add a couple of lines of code to
read the value from the control and store it in the array.

Dave
 
G

Guest

No not a C++ issue, an inexperienced beginner issue. It's the couple lines of
code
and reading the value of the control I'm not sure of . Here is my Save
Button code.

private: System::Void btnSave_Click(System::Object * sender,
System::EventArgs * e)
{
FileStream *stmScore = 0;
BinaryWriter *bnwScore = 0;

if( this->txtScored->Text->Equals(S"") )
{
MessageBox::Show(S"The report cannot be saved without a score entered");
this->txtScored->Focus();
return;
}
if( this->txtAllowed->Text->Equals(S"") )
{
MessageBox::Show(S"The report cannot be saved without a score entered");
this->txtAllowed->Focus();
return;
}

String *strFilename = String::Concat(this->txtScored->Text,
this->txtAllowed->Text);
this->saveFileDialog1->FileName = strFilename;
if( this->saveFileDialog1->ShowDialog() == DialogResult::OK )
{
if( File::Exists(this->saveFileDialog1->FileName) )
 
D

David Lowndes

No not a C++ issue, an inexperienced beginner issue. It's the couple lines of
code
and reading the value of the control I'm not sure of . Here is my Save
Button code.
...

I'm not sure of the relevance of what you've shown to what you say
you're trying to do.

However, to read the control value and store it in your array, you'll
need to do something like this:

{
int CurPos = trackBar1->Value - 1;
... Check CurPos is valid before using it of course...

Team[Curpos]->Score = System::Int32::parse( txtScored->Text );
....
}

Dave
 
G

Guest

I think this line of code is where I was having my confusion
(Team[Curpos]->Score = System::Int32::parse( txtScored->Text );).
I will try this and see if it will produce the results I am looking for.
Sorry for my lack of clarity, but thanks for your input. I'm sure it will
help.

David Lowndes said:
No not a C++ issue, an inexperienced beginner issue. It's the couple lines of
code
and reading the value of the control I'm not sure of . Here is my Save
Button code.
...

I'm not sure of the relevance of what you've shown to what you say
you're trying to do.

However, to read the control value and store it in your array, you'll
need to do something like this:

{
int CurPos = trackBar1->Value - 1;
... Check CurPos is valid before using it of course...

Team[Curpos]->Score = System::Int32::parse( txtScored->Text );
....
}

Dave
 
G

Guest

That line of code did fix my dilema. Thank you. I just have some minor issues
to work on now, but that was what I needed. Much appreciated.

David Lowndes said:
No not a C++ issue, an inexperienced beginner issue. It's the couple lines of
code
and reading the value of the control I'm not sure of . Here is my Save
Button code.
...

I'm not sure of the relevance of what you've shown to what you say
you're trying to do.

However, to read the control value and store it in your array, you'll
need to do something like this:

{
int CurPos = trackBar1->Value - 1;
... Check CurPos is valid before using it of course...

Team[Curpos]->Score = System::Int32::parse( txtScored->Text );
....
}

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top