Novice Question - Array Elements 
Author Message
 Novice Question - Array Elements

The game project I am working on has a section that has a horse race. I
want the program to pick 3 winners from a list of 12. (I plan to use
random code I got previously from this group). The difference is that I
want it to return a string and not just a number. The horses are
numbered followed by their name.

Example
First Place = 6.  Half Way There
Second Place = 2. Can't Get There From Here
Third Place = 10. Daddies Nag

The problem I am having is how do I create and designate the array
elements so that it will return the number AND name of horse in an
editfield (or listbox)

I tried using 12 checkboxes, and setting the captions to the number and
names of the horses. But I cant figure out how to get horseArray to
recognize the checkboxes as the elements in the array. Checkboxes
indexes are set from 0 to 11. It doesnt have to be checkboxes. That was
my way of trying to create the array elements.

Any suggestions???

J5



Sat, 30 Nov 2002 03:00:00 GMT  
 Novice Question - Array Elements
'This will put a checkmark next to the appropiate checkboxes.
'Assume your checkboxes are named chkHorse(0) to chkHorse(11)
dim i,x as Integer

for i = 1 to 3
 x = 'call your random routine here
 chkHorse(x).value = 1 'check the appropiate checkbox
next

Take care,

John

In article


Quote:
> The game project I am working on has a section that has a horse race.
I
> want the program to pick 3 winners from a list of 12. (I plan to use
> random code I got previously from this group). The difference is that
I
> want it to return a string and not just a number. The horses are
> numbered followed by their name.

> Example
> First Place = 6.  Half Way There
> Second Place = 2. Can't Get There From Here
> Third Place = 10. Daddies Nag

> The problem I am having is how do I create and designate the array
> elements so that it will return the number AND name of horse in an
> editfield (or listbox)

> I tried using 12 checkboxes, and setting the captions to the number
and
> names of the horses. But I cant figure out how to get horseArray to
> recognize the checkboxes as the elements in the array. Checkboxes
> indexes are set from 0 to 11. It doesnt have to be checkboxes. That
was
> my way of trying to create the array elements.

> Any suggestions???

> J5

Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 30 Nov 2002 03:00:00 GMT  
 Novice Question - Array Elements


Ahhaaa, now I see how I failed to get the array to recognize the
checkboxes as elements in the array. Making progress.

Thing is to activate the checkmarks would require 36 checkboxes. First
Second and Third place. Seems easier to delacre the array elements as a
string and diplay them in a editfiled
Maybe something like
dim myHorseArray (11) as string

 1 Half Way There = myHorse(0)  // maybe thats backwards
etc etc to fill the array with string elements

//random code here

editfield1.text="First Place  " + str(output(1)) +" € " + "Second Place
"+ str(output(2)) +" € " + "Third Place  "+str(output(3))   //race
results displayed

will this work?? or am I out in left field???

In the mean time I'll take your suggestion and see if I can work it out.

Thank You

J5

Quote:
> 'This will put a checkmark next to the appropiate checkboxes.
> 'Assume your checkboxes are named chkHorse(0) to chkHorse(11)
> dim i,x as Integer

> for i = 1 to 3
>  x = 'call your random routine here
>  chkHorse(x).value = 1 'check the appropiate checkbox
> next

> Take care,

> John

Snip

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sat, 30 Nov 2002 03:00:00 GMT  
 Novice Question - Array Elements
Well, if you'll be using strings and editfields, then you could do it
this way:

'We assume that you have created three edit fields as part of an array
'named myEditField(0) to myEditField(2)

Dim myStrings(11) as String
Dim i,x as Integer

myStrings(0) = "Horsey"
myStrings(1) = "OtherHorsey"
'etc.

'We have to use 0 to 2, to match the EditFields array
For i = 0 to 2
 x = 'your random generation routine
 myEditField(i) = myStrings(x)
Next

'Notice that you could have skipped the intermediate variable x,
'by substituing it by your randomizing routine

Dim myStrings(11) as String
Dim i as Integer

myStrings(0) = "Horsey"
myStrings(1) = "OtherHorsey"
'etc.

'We have to use 0 to 2, to match the EditFields array
For i = 0 to 2
 myEditField(i) = myStrings(myRandomizingRoutineHere)
Next

Take care,

John

In article


Quote:


> Ahhaaa, now I see how I failed to get the array to recognize the
> checkboxes as elements in the array. Making progress.

> Thing is to activate the checkmarks would require 36 checkboxes. First
> Second and Third place. Seems easier to delacre the array elements as
a
> string and diplay them in a editfiled
> Maybe something like
> dim myHorseArray (11) as string

>  1 Half Way There = myHorse(0)  // maybe thats backwards
> etc etc to fill the array with string elements

> //random code here

> editfield1.text="First Place  " + str(output(1)) +" € " + "Second
Place
> "+ str(output(2)) +" € " + "Third Place  "+str(output(3))   //race
> results displayed

> will this work?? or am I out in left field???

> In the mean time I'll take your suggestion and see if I can work it
out.

> Thank You

> J5

> > 'This will put a checkmark next to the appropiate checkboxes.
> > 'Assume your checkboxes are named chkHorse(0) to chkHorse(11)
> > dim i,x as Integer

> > for i = 1 to 3
> >  x = 'call your random routine here
> >  chkHorse(x).value = 1 'check the appropiate checkbox
> > next

> > Take care,

> > John

> Snip

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sun, 01 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements

Quote:

> The game project I am working on has a section that has a horse race. I
> want the program to pick 3 winners from a list of 12. (I plan to use
> random code I got previously from this group). The difference is that I
> want it to return a string and not just a number. The horses are
> numbered followed by their name.

> Example
> First Place = 6.  Half Way There
> Second Place = 2. Can't Get There From Here
> Third Place = 10. Daddies Nag

> The problem I am having is how do I create and designate the array
> elements so that it will return the number AND name of horse in an
> editfield (or listbox)

> I tried using 12 checkboxes, and setting the captions to the number and
> names of the horses. But I cant figure out how to get horseArray to
> recognize the checkboxes as the elements in the array. Checkboxes
> indexes are set from 0 to 11. It doesnt have to be checkboxes. That was
> my way of trying to create the array elements.

> Any suggestions???

> J5

        Your life will be simpler all around if you create a Horse class
and simply extract the name and number from the object when necessary.

        -jc

--

* Home page:  http://members.tripod.com/~afeldspar/index.html
*          The home of >>Failed Pilots Playhouse<<
* "Better you hold me close than understand..."  Thomas Dolby



Mon, 02 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements

Quote:

>         Your life will be simpler all around if you create a Horse class
> and simply extract the name and number from the object when necessary.

and don't forget to create a farrier class that will take care of your
new companions ;-)


Tue, 03 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements
Great
A couple REAL good (pun intended) suggestions.
Thank You for the suggestions. This will give me something to play
around with and see what works best.

Thanks Again

J5

In article

Quote:



> Ahhaaa, now I see how I failed to get the array to recognize the
> checkboxes as elements in the array. Making progress.

> Thing is to activate the checkmarks would require 36 checkboxes. First
> Second and Third place. Seems easier to delacre the array elements as a
> string and diplay them in a editfiled
> Maybe something like
> dim myHorseArray (11) as string

>  1 Half Way There = myHorse(0)  // maybe thats backwards
> etc etc to fill the array with string elements

> //random code here

> editfield1.text="First Place  " + str(output(1)) +" € " + "Second Place
> "+ str(output(2)) +" € " + "Third Place  "+str(output(3))   //race
> results displayed

> will this work?? or am I out in left field???

> In the mean time I'll take your suggestion and see if I can work it out.

> Thank You

> J5

> > 'This will put a checkmark next to the appropiate checkboxes.
> > 'Assume your checkboxes are named chkHorse(0) to chkHorse(11)
> > dim i,x as Integer

> > for i = 1 to 3
> >  x = 'call your random routine here
> >  chkHorse(x).value = 1 'check the appropiate checkbox
> > next

> > Take care,

> > John

> Snip

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.



Wed, 04 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements

Although I pretty much have my array problem solved I am curious about
your suggestion about creating a class. This sounds like it could be
educational if nothing else. How would I go about this. I know how to
create a "class" but where would the individual horse number and names
go?? Create a method for each, I'm guessing here. And how would I call
on the class when I want the race results(i.e. when pushbutton is
clicked on). Any help to get me headed in the right direction would be
much appreciated.

Thanks

J5
<<snip>>

Quote:

>         Your life will be simpler all around if you create a Horse class
> and simply extract the name and number from the object when necessary.

>         -jc



Sun, 08 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements

Quote:

> Although I pretty much have my array problem solved I am curious about
> your suggestion about creating a class. This sounds like it could be
> educational if nothing else. How would I go about this. I know how to
> create a "class" but where would the individual horse number and names
> go?? Create a method for each, I'm guessing here. And how would I call
> on the class when I want the race results(i.e. when pushbutton is
> clicked on). Any help to get me headed in the right direction would be
> much appreciated.

> Thanks

In your horse class you define 2 properties (not methods): number as
Integer and name as String, then you define horses with an array eg
h(10) as Horse. Now you have an access to each horse's name and number :
h(1).name or h(10).number etc...


Mon, 09 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements
Would name of array be the same as the name as the class?

J5


Quote:


> > Although I pretty much have my array problem solved I am curious about
> > your suggestion about creating a class. This sounds like it could be
> > educational if nothing else. How would I go about this. I know how to
> > create a "class" but where would the individual horse number and names
> > go?? Create a method for each, I'm guessing here. And how would I call
> > on the class when I want the race results(i.e. when pushbutton is
> > clicked on). Any help to get me headed in the right direction would be
> > much appreciated.

> > Thanks

> In your horse class you define 2 properties (not methods): number as
> Integer and name as String, then you define horses with an array eg
> h(10) as Horse. Now you have an access to each horse's name and number :
> h(1).name or h(10).number etc...



Mon, 09 Dec 2002 03:00:00 GMT  
 Novice Question - Array Elements

Quote:

> Would name of array be the same as the name as the class?

No. This is the same as when you define an integer array :

dim i(10) as Integer.

The array's declaration isn't Integer but i(10).
With the declaration :

dim h(10) as Horse

you declare 11 variables h(0)..h(10) which belong to the Horse class.



Tue, 10 Dec 2002 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Shifting array element & regex on array element

2. Novice question -- inserting element in list

3. Arrays: Build array in multiple for loops or replace array elements

4. Adding an element in an array of cluster of 2 elements

5. FFI question: Setting array elements

6. array element (matrix) question

7. question about one-element arrays

8. Access Array Elements by Arrays Reference

9. for every element of array find bounds in another array

10. Array and creation of the elements of the array

11. Adjustable array dimensions specified via array element?

12. creation of array elements and write traces on an array

 

 
Powered by phpBB® Forum Software