newbie variable array question

kunfuzed1
09-10-2003, 07:03 PM
Alright guys..
if you would be so kind as to tell me if im on the right track or not..

I realize that with control arrays, i can use WhateverControl(index) to reference the control and vb controls whatever one has focus or whatever.. i dont know if im explaining that quite right.. but hopefully you'll get it.

What I want to know is if I can do the same thing somehow with variables.. I have a variable array dtStartTime(48) as date

what i'd like to do is for each set of controls i have, automatically put the information into a variable array. So far im not doing it right.


Option Explicit
dim dtStartTime(48) as Date
dim dtEndTime(48) as Date


Private Sub cmdCalculate_Click(Index As Integer)

dtStartTime(Index) = CDate(txtStartTime(Index).Text)
dtEndTime(Index) = CDate(txtEndTime(Index).Text)

MsgBox dtStartTime(Index) & " " & dtEndTime(Index)
End Sub


I KNOW this isnt correct, obviously because it doesnt work right and it just doesn't even look right to me.. but my question is, is it possible to do what i want? I can call control names by (index) and it does what i want it to do as far as putting the right information in the right places.. and i realize that index is declared as an integer by the control name, is there something i can do like that for a variable array?

passel
09-10-2003, 07:13 PM
I'm not sure what problem you are having. It works fine for me.

You are declaring the variables in the General Declarations area, correct.

kunfuzed1
09-10-2003, 07:21 PM
I'm not sure what problem you are having. It works fine for me.

You are declaring the variables in the General Declarations area, correct.

oh, sorry, i didnt explain it well enough.. i'll try again..
this is still from the same program i was working on with my other questions .. i'll post a screen shot again. What im trying to do is get each player to get the starting time and ending time into those two variables..
So player 1 goes into variable(0) , Player 2 goes into variable(1) etc.
right now as that code stands.. each control from the array will add into those variables.. i want each player to be in a seperate variable in the array..
And yes, i am declaring the variables in the general declarations area..

passel
09-10-2003, 07:31 PM
Ok..., I still not sure what problem you are having. I put your code in a
quick test, and it works as expected.

Here's the code.

Option Explicit
Dim dtStartTime(48) As Date
Dim dtEndTime(48) As Date


Private Sub cmdCalculate_Click(Index As Integer)

dtStartTime(Index) = CDate(txtStartTime(Index).Text)
dtEndTime(Index) = CDate(txtEndTime(Index).Text)

MsgBox dtStartTime(Index) & " " & dtEndTime(Index)
End Sub

Here's a printout from the immediate window, after entering the data
as shown in the attach picture.

for i = 0 to 3: print dtStartTime(i): next
10:00:00
8:23:00
8:34:00
0:00:00

kunfuzed1
09-10-2003, 08:54 PM
dude, i dunno what happened.. it does work now..
i must've changed something inadvertently to correct it before i posted it...
i'm sorry to waste your time.. well i didnt really, you made me realize it already works.. i was trying to correct something that no longer needed to be corrected.. makes me wonder how long i woudlve sat there looking at the code trying to fix something that wasn't broke...

Thanks again dude, as always, you are the one of the few that keep me from going insane and smashing my keyboard.
I appriciate your time and efforts.

Jim

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum