TextBox.Visible = True ... not working

G

Guest

Hi there,
I use the code below to show some textboxes and images while I play a sound
( explaining these images)... the problem that I can't solve is that
sometimes the code works and sometimes not. The sounds are correct all the
time but sometimes after the first textbox the other objects remain
invisible. At the end the first textbox turn invisible so that part works
too.
I patched this together from the net and my VBA is not good enough to single
out the mistake here and I would appreciate any help.

Thank you,
Özgür


Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000


Private Sub Label2_Click()
If CheckBox1.Value = True Then
TextBox2.Visible = True
WAVFile = "Scenario2.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 18
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

TextBox3.Visible = True
Image3.Visible = True
WAVFile = "Scenario3.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 15
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
Image3.Visible = False
Image2.Visible = True

newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime

TextBox2.Visible = False
TextBox3.Visible = False
Image2.Visible = False
Image3.Visible = False
End If
newHour = ""
newMinute = ""
newSecond = ""
End Sub
 
P

paul.robinson

Hi
Try putting in some "DoEvents" lines after making the buttons visible.
This often sorts out this kind of graphics updating problem. I didn't
look at your code in detail though, so it may be something else!
regards
Paul

e.g.
TextBox2.Visible = True
DoEvents
 
G

Guest

Paul thanks for the reply will try it out and let you know about the result.

Özgür
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top