Results 1 to 3 of 3
-
01-19-2005, 01:33 AM #1Web Hosting Guru
- Join Date
- Mar 2004
- Posts
- 269
Need a little Help with Borland C++
Hope this is the right place to post this. Its probably a simple answer but its eluded me.
In my program i have 15 images labelled img_0, img_1, img_2... img_14.
I have created a random number and stored it in the integer 'i' using :
i = rand()%14;
Now i want to be able to select my images at randomly using the random value in 'i', by doing something along the lines of:
img_i->Visible = true;
However i keep getting an error saying the value assigned to 'i' isn't being used, which means i am not using it properly. I have tried various brackets around it but no avail.
Here is the complete code for that section.
do
{
int i;
i = rand()%14;
if (img_i->Visible == true)
{
lbl_count->Caption = StrToInt(lbl_count->Caption) -1;
img_i->Height = 0;
img_i->Width = 0;
img_i->Visible = false;
lbl_pick->Caption = StrToInt(lbl_pick->Caption) -1;
}
}
while (StrToInt(lbl_pick->Caption) > 0);
Thanks for any help.
-
01-19-2005, 03:35 AM #2
Moved to Programming Discussion.
-
01-19-2005, 03:46 AM #3Web Hosting Guru
- Join Date
- Aug 2000
- Location
- Redmond, WA
- Posts
- 310
I believe that your issue is due to the use of "img_i". In C/C++ this statement says that you are accessing variable img_i (not img_9 or img_0 like some scripting/interpreted languages) and checking the status of it's Visible property. Your code does not actually use i at all after assigning the random number to it. The best option that I can come up with at this moment would be to load your images into an array and use i to index into it. It would look something like this:
PHP Code:Images*[] img = new Images*[15];
/*
Do stuff to initialize the Image objects and store them in the array
*/
do
{
int i;
i = rand()%14;
if (img[i]->Visible == true)
{
lbl_count->Caption = StrToInt(lbl_count->Caption) -1;
img[i]->Height = 0;
img[i]->Width = 0;
img[i]->Visible = false;
lbl_pick->Caption = StrToInt(lbl_pick->Caption) -1;
}
}
while (StrToInt(lbl_pick->Caption) > 0);
Chris Spangler
chris@thespanglers.net