|
-
Jan 29th, 2001, 10:26 PM
#1
Just a basic array question that doesn't seem to work for me.
My code:
Dim tmp(1 To 1000) As Long
Car1End = timer
car1Lap = Val(txtCarLap1.Text)
txtCarLap1.Text = car1Lap + 1
tmp(car1Lap) = Car1End
What I'm trying to do is store each lap in a array, and then find the average. Car1End is a integer, and so is car1Lap. Now, I get a "Subscript out of range" error. Can YOU help?
Thanks.
-
Jan 29th, 2001, 10:36 PM
#2
Fanatic Member
Try this .....
Code:
Dim tmp(1 To 1000) As Long
Car1End = timer
txtCarLap1.Text = car1Lap + 1
car1Lap = Val(txtCarLap1.Text)
tmp(car1Lap) = Car1End
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Jan 29th, 2001, 10:42 PM
#3
YEAH!
THANKS!
That worked...
I'm not sure why though..
Can you possible explain what happened?
-
Jan 29th, 2001, 10:52 PM
#4
You needed an integer value for the index of the array, the Val() function converts say the character "1" to the number 1. That's why it works now
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jan 29th, 2001, 11:29 PM
#5
Fanatic Member
The Subscript out of range error occurs when you try to access an element in an array which does not exist, and in the code you provided the carLap1 variable was not being incremented the first time the code is ran because you were retrieving it's value from an empty textbox which filled the variable with 0, and considering your array starts at element one it was looking for a value that doesn't exist.
This code would also work...
Code:
Dim tmp(0 To 999) As Long 'still 1000 elements but the first is 0
Car1End = timer
car1Lap = Val(txtCarLap1.Text) ' will return 0 the first time code is ran
txtCarLap1.Text = car1Lap + 1
tmp(car1Lap) = Car1End
Hope that makes things clearer.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|