|
-
Oct 3rd, 2002, 06:24 PM
#1
Thread Starter
PowerPoster
Looping problem...
I am trying to make a form flash colours whilst some other activity takes place, and then stop. I use the following functions to flash the form.
VB Code:
Private Function RunWalkthrough_0_1()
'Explain the display
Call FlashForm(frmControlHead)
'Do stuff.... lalala
Call StopFlashControl
End Function
Public Sub FlashForm(frmForm As Form, Optional ColourFlash = -1)
On Error Resume Next
'Flash form between two colours every second
flgFlashControl = True
'Set flash colour and original colour
Dim OriginalColour As Long, FlashColour As Long
FlashColour = IIf((ColourFlash < 0), DEFAULT_FLASH_COLOUR, ColourFlash)
OriginalColour = frmForm.BackColor
'Flash form
Do While (flgFlashControl)
DoEvents
'Swap colours
If frmForm.BackColor = FlashColour Then
frmForm.BackColor = OriginalColour
Else
frmForm.BackColor = FlashColour
End If
'Wait
PauseMe (50000)
Loop
'Return form colour
frmForm.BackColor = OriginalColour
End Sub
Public Sub StopFlashControl()
'Reset flashing flag
flgFlashControl = False
End Sub
'Pause system in a loop temporarily
Public Sub PauseMe(lngPauseDuration As Long)
Dim i As Long
Do Until i = lngPauseDuration
i = i + 1
DoEvents
Loop
End Sub
But the code never seems to leave the FlashForm function. StopFlashControl is never callled. Bit of help, please?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 06:33 PM
#2
Junior Member
i could be wrong......but it looks like you never get out of your do while loop in FlashForm....
it looks like flgFlashControl is always true
so it never gets to the end of FlashForm.....hence never getting back to RunWalkthrough_0_1 hence never getting to StopFlashControl
i am new to vb so please ignore post if i am off base! - lol
-
Oct 3rd, 2002, 06:34 PM
#3
Fanatic Member
You'll have to use a timer control, and place some of the code in there. With it coded as currently, executing won't continue until the function Flash... returns. What you need is a timer event that sets the flash flag to false at some point... or even better, place the flashing code in a timer with an interval of 2000, then enable the timer where you call the Flash... function, and disable the timer when you want flashing to cease.
-
Oct 3rd, 2002, 06:35 PM
#4
Fanatic Member
flgFlashControl is never changed within your Do Loop, so it will always be True so the loop will just keep going and going...
-
Oct 3rd, 2002, 06:40 PM
#5
Thread Starter
PowerPoster
I'm aware that the flag won't change within the loop, but it's a public flag, and I thought by calling another function, it would set it false.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 06:42 PM
#6
Fanatic Member
It will. Try
VB Code:
Public flgFlashControl
Private Sub Command1_Click()
RunWalkthrough_0_1
End Sub
Private Sub Command2_Click()
Call StopFlashControl
End Sub
-
Oct 3rd, 2002, 06:47 PM
#7
Thread Starter
PowerPoster
But it's not. That's the problem...
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 07:14 PM
#8
Fanatic Member
I see. DoEvents lets you "jump" out of the VB code and fire a new event. But I think you want to just have the code run two functions at the same time. Timer control solution would work. Otherwise maybe someone else can provide some type of threading/hooking sort of explanation or solution.
-
Oct 3rd, 2002, 07:27 PM
#9
Thread Starter
PowerPoster
Threading would probably solve it, but I gather VB isn't so good at that. 
Have got a ****ty workaround for now. Time constraints and all that.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 07:31 PM
#10
rjlohan - Gday,
You could place a counter in the loop, and when that value is reaced
Exit Do, Or
Set an external Boolean Flag, that if detected in your loop will
Exit Do.
(Either way you go do without the StopFlashing Sub and handle
the 'Stop' within the Loop 'Counter, or Bololean Flag)
As mentioned, the problem is you will never get to the StopFlashing Sub, cause ur in a loop (as you know).

Bruce.
-
Oct 3rd, 2002, 07:34 PM
#11
Thread Starter
PowerPoster
Counter's no good unfortunately, as the end of the loop varies based on the length (in seconds) of an audio file. I'm trying to do some automated walkthrough stuff in a hurry, so I'm just gonna go with my 'hack' solution for now.
Cheers,
RJ
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 08:29 PM
#12
PowerPoster
What are you trying to do rj?
Stop the flashing of the form?
-
Oct 3rd, 2002, 08:31 PM
#13
Fanatic Member
I think he wants the form to flash while VB is running other code. I'd use the Timer control. Thought that's what Timer was for. But I don't know.
-
Oct 3rd, 2002, 08:43 PM
#14
Thread Starter
PowerPoster
See, the problem is, that I'm also playing audio, and I want to synchronise a series of events. It's a right pain in the arse, I tell you...
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 3rd, 2002, 09:10 PM
#15
PowerPoster
Ok how's this:
You'll need a command button a timer! Just for testing! Set the timer enabled to false to start with and it's interval to 5000!
VB Code:
Dim flgFlashControl As Boolean
Private Function RunWalkthrough_0_1()
'Explain the display
Call FlashForm(frmControlHead)
'Do stuff.... lalala
Call StopFlashControl
End Function
Public Sub FlashForm(frmForm As Form, Optional ColourFlash = -1)
On Error Resume Next
'Flash form between two colours every second
Call writing
'Set flash colour and original colour
Dim OriginalColour As Long, FlashColour As Long
FlashColour = IIf((ColourFlash < 0), DEFAULT_FLASH_COLOUR, ColourFlash)
OriginalColour = frmForm.BackColor
'Flash form
DoEvents
Do While (flgFlashControl = True)
DoEvents
'Swap colours
If frmForm.BackColor = FlashColour Then
frmForm.BackColor = OriginalColour
Else
frmForm.BackColor = FlashColour
End If
'Wait
PauseMe (10000)
Loop
DoEvents
'Return form colour
frmForm.BackColor = OriginalColour
End Sub
Public Sub StopFlashControl()
'Reset flashing flag
flgFlashControl = False
End Sub
'Pause system in a loop temporarily
Public Sub PauseMe(lngPauseDuration As Long)
DoEvents
Dim i As Long
Do Until i = lngPauseDuration
DoEvents
i = i + 1
DoEvents
DoEvents
Loop
DoEvents
End Sub
Private Sub Command1_Click()
flgFlashControl = True
Call FlashForm(Me, red)
End Sub
Public Sub writing()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text1.Text = "jbjabsdlvkbas"
flgFlashControl = False
End Sub
The Writing sub doesnt have to be launching a timer it could play music as well!
b
-
Oct 3rd, 2002, 09:15 PM
#16
Fanatic Member
Best solution
Ditch vb6 get vb.net and use multithreading to solve your problem
Much less code too

Glad to be of service to ya
-
Oct 3rd, 2002, 09:42 PM
#17
RJ,
Is there an event for the Audio file 'Finished'/'Load Complete' (or whatever it is) ?
-
Oct 3rd, 2002, 09:47 PM
#18
Thread Starter
PowerPoster
Only if I use that MCI control, which I'm not.
I'm using sndPlaySound API. I'm sure I had a reason at some stage.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 4th, 2002, 12:30 AM
#19
PowerPoster
i assume my way didnt work for you?
-
Oct 4th, 2002, 12:32 AM
#20
Thread Starter
PowerPoster
Wasn't really appropriate to the situation I'm afraid.
I'm thinking I may try the MCI control, and use its events to help me. But that will only work if I can implement function pointers in VB. Is that possible?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 4th, 2002, 12:51 AM
#21
PowerPoster
Originally posted by rjlohan
Wasn't really appropriate to the situation I'm afraid.
I'm thinking I may try the MCI control, and use its events to help me. But that will only work if I can implement function pointers in VB. Is that possible?
What there's a situation where a carton of beer doesnt help??

*covers ears*
-
Oct 4th, 2002, 12:54 AM
#22
Thread Starter
PowerPoster
When did you say anything about beer??
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
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
|