Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I'm using the following code bu 1

Status
Not open for further replies.

grobermatic

Technical User
Dec 21, 2002
153
GB
Hi, I'm using the following code but at the line where I've placed "***" it completely locks access up. I have to exit Access through the Task Manager. I need to be able to use the form from where the code was activated whist its running as its constantlyu checking the status of a control on a form.

Function Game1_Procedure()

Dim StartTime As Date
Dim EndTime As Date
Dim TotalTime As Date
Dim booFinished As Boolean

StartTime = TIME()
booFinished = False

Do Until booFinished = True
*** If Forms!frmGameBoard1![Box15].BackColor = 65280 Then
booFinished = True
Exit Do
End If
Loop

EndTime = TIME()
TotalTime = EndTime - StartTime
MsgBox TotalTime

End Function

(Please forgive the crudeness of my code as I am self taught and am fully aware that its not the prettiest code on the world!)

Any ideas why this happens

Thanks

Craig
 
Do Until booFinished = True
If Forms!frmGameBoard1![Box15].BackColor = 65280 Then
booFinished = True
Exit Do
End If
Loop

A few thoughts about this code:
=You don't need the "Exit Do" line. That's why you have the Do Until line.
=There's no mechanism to end the loop if the color is _not_ 65280, so it's probably just going into an infinite loop. You could probably stop the code by hitting Ctrl-Break.

What are you trying to do? I would say you've got to have some way in the loop to set the color to what you want it to be. Are you expecting some outside process to change the color? What process is that? Remember that VBA works on an event-driven model. There's probably no need for the loop. You can probably find a different event to change the color.

If you describe what you're trying to do, I'm sure we'll be able to offer strategy tips.

Jeremy =============
Jeremy Wallace
AlphaBet City Dataworks

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Thanks for your comments...

Ok don't laugh...

Its just an office game I'm working on... much like the Buzz Game where you have to move a metal loop along a metal wire witout touching them and if you do it Buzzes.

I have a form with a path drawn out in lines and at different points along the way are boxes 1 thru 15.

The user moves along the line path and as they pass though each box it changes from Red to Green (using the MouseMove property). If they move out of the path the boxes go back to Red (again using the MounsMove property for the detail section of the form)

So its the user who changes the colour of Box15 by moving their mouse over the control.

I intended the loop to be constatnly checking to see if the colour has changed so that it can stop the timer and present the total time it took the player to complete the game.

This is the first time I've used a Loop so I'm a bit unsteady. I intended the loop to continue until the user has either completed the game or failed by moving their cursor out of the path.

Thanks again

Craig
 
Well, get rid of the Exit Do and after the end if put a DoEvents. But I don't think it's going to work out so well. Access is really not a very good platform for developing games. It's just not slick enough in handling asynchronous events.

Jeremy =============
Jeremy Wallace
AlphaBet City Dataworks

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Thanks for your help Jeremy, I think its probably best to quit while I'm ahead with this one.

Thanks again

Craig
 
Hi grobermatic,

This should accomplish what you were trying to do:

Dim StartTime As Date 'declarations section of form
Dim EndTime As Date 'declarations section of form
Dim TotalTime As Date 'declarations section of form

Private Sub Form_Load()
StartTime = Time()
End Sub

Private Sub Form_Timer() 'Timer Interval set to 250, ie looks 4 times per second at Box15
If Me!Box15.BackColor = 65280 Then
EndTime = Time()
TotalTime = EndTime - StartTime
MsgBox TotalTime
Me!Box15.BackColor = 65281 'call your procedures here
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top