Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Very Basic Array Problems

Author
Message
Epiphora
12
Years of Service
User Offline
Joined: 28th May 2012
Location:
Posted: 30th May 2012 12:22
Hi, I'm not even sure how to add code to this forum so please bear with me.

I have been following Hamish's basic tutorial and all was going reasonably well until I got to the MULTIDIMENSIONAL ARRAYS section.

Essentially there are a couple of lines of code that I can't understand:

`Loop through runners
For x=1 to 2
`Generate a base time so that all the runners times can be about the same
baseTime = rnd(10)+10

`Loop through times
For y=1 to 4
`Offset each time by a slight bit
LapTimes#(x,y) = baseTime+(rnd(50)-25)/10.0
`Add to the average time
Inc LapTimes#(x,5), LapTimes#(x,y)
Next y

`Complete average calculations[b]
[b]LapTimes#(x,5) = LapTimes#(x,5) / 5.0
[/b][/b]
Next x

Basically it is the (x,y) and (x,5) variables that I can't figure out and especially this line:

Inc LapTimes#(x,5), LapTimes#(x,y)

What is the inclement in this line:

If some one can explain that line by line would be a massive help and also offer any more examples I can play around with would be great.

The full code is as follows:

`Loop through runners
For x=1 to 2
`Generate a base time so that all the runners times can be about the same
baseTime = rnd(10)+10

`Loop through times
For y=1 to 4
`Offset each time by a slight bit
LapTimes#(x,y) = baseTime+(rnd(50)-25)/10.0
`Add to the average time
Inc LapTimes#(x,5), LapTimes#(x,y)
Next y

`Complete average calculations
LapTimes#(x,5) = LapTimes#(x,5) / 4.0
Next x

`Draw the results up in a table
For x=1 to 2
`Write runner numbers
Set cursor x*150,0
Print "Runner ",x

`Write lap times and average time
For y=1 to 5
Set cursor x*150,y*20
Print LapTimes#(x,y)
Next y
Next x

`Write lap time names
For x=1 to 4
Set cursor 50,x*20
Print "Lap Time ",x
Next x

`Write "Average"
Set cursor 50,100
Print "Average"
Wait key

(and if some one can tell me how to add snippets that would be great too.)

Thanks for your time
RonsWare
14
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 31st May 2012 09:16
Hi there.

First copy your code.

Then select the code button.

Then paste your code.

End then select te code button again.

Hope this helped.

cheers Ron.

Programming is learning
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 31st May 2012 13:09
Quote: "Inc LapTimes#(x,5), LapTimes#(x,y)

What is the inclement in this line:"


If I've read the code correctly it looks like it's adding up 'LapTimes' for each person x, where (x,5) is the total. When we get to this line:

LapTimes#(x,5) = LapTimes#(x,5) / 4.0

the division calculates the average.

In short, lapTimes(x,5) = ( (x,1)+(x,2)+(x,3)+(x,4) ) / 4

Epiphora
12
Years of Service
User Offline
Joined: 28th May 2012
Location:
Posted: 31st May 2012 15:47
Thanks. slowly getting the hang of it, then getting confused again, then understanding a little more.
Epiphora
12
Years of Service
User Offline
Joined: 28th May 2012
Location:
Posted: 31st May 2012 19:59
@ Ron thanks a lot
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 2nd Jun 2012 04:30
Hopefully this will help you on multidimensional arrays.

Hopefully, that makes multidimensional arrays a little easier to understand!

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Epiphora
12
Years of Service
User Offline
Joined: 28th May 2012
Location:
Posted: 6th Jun 2012 22:41
Nice, thanks for that

Login to post a reply

Server time is: 2024-11-23 20:51:04
Your offset time is: 2024-11-23 20:51:04