How to make a command occur only once
Hey,
I have a command which has to occur when an object becomes visible. However the command must occur only once, and no more times. so i cant put it in a timer section. Where should i put it, or how can i make the command happen when the object become visible, and then ignore the fact that the object is still visible?
Re: How to make a command occur only once
This should do it:
VB Code:
Dim Command_Once As Boolean
Public Sub Game_Loop()
Do
DoEvents
'This is your part when you want an object to do
'something once
If Command_Once = False And Object_Whatever.Visible = True then
Command_Once = True
'Do whatever that command is
End If
'Draw stuff here
Loop
End Sub
Re: How to make a command occur only once
This is almost along the lines of pseudo-code.. but perhaps it will help. The idea is to use a boolean that keeps it's value between calls. This could be a Global, or a local static.
VB Code:
Private Sub Form_Load()
'Start with an invisible control
myControl.Visible = False
End Sub
Private Sub Command1_Click()
'In one event, make the control visible.
myControl.Visible = True
End Sub
Private Sub Command2_Click()
'In another event, check for visibility.
'Use a static boolean to ensure the code after the check
'runs only once.
Static Switch As Boolean
If myControl.Visible = True And Switch = False Then
MsgBox "Control is visible"
Switch = True
End If
End Sub