Solved

Sleep API Function?? Please help.

Posted on 2003-11-19
6
2,216 Views
Last Modified: 2010-05-01
Hi Folks,

I am currently creating my first VB6 project(Game of Pairs). The problem that i have is that when i run the code below the sleep function doesn't allow the second button .visible = false. So when you click, the button is not invisible. the first button (case = 1) works fine.

Private Sub Command3_Click(Index As Integer)

Dim X As Integer
Dim W As Integer

NumClick = NumClick + 1

For X = 0 To 15

    If Index = X Then
           
         Select Case NumClick
                Case Is = 1
                    Command3(X).Visible = False
                Case Is = 2
                    Command3(X).Visible = False  '     <=====  it doesn't do this
                    Call Sleep(2000)
                    Call Check_Pairs
         End Select
                   
    End If
   
Next X

If NumClick = 2 Then NumClick = 0 ' reset variable after 2 clicks!
End Sub

I have even tried putting a For X loop in between:

Command3(X).Visible = False

for x = 1 to 500
textbox1.text = "this is a wast of time!!!"
next x

Call Sleep(2000)

Even after this the button doesnt change to invisible! Does anyone know how to fix this??!! Please.





0
Comment
Question by:craigpike
6 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 50 total points
ID: 9781463
Put DoEvents after

Command3(X).Visible = False  '     <=====  it doesn't do this
Doevents
0
 
LVL 14

Expert Comment

by:aelatik
ID: 9781481
Doevents lets the system process everything before it continues. Without it your app will mostly not responding.
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9781495
DoEvents causes other events in the queue to be processed first. You may just want to force a refresh of the screen.

               Case Is = 2
                    Command3(X).Visible = False  '     <=====  it doesn't do this
                    Command3.Refresh  ' Not sure if this will work by itself.
                    Form1.Refresh ' This should work, but it the previous line works, then it requires less painting time.
                    Call Sleep(2000)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:excitebite
ID: 9782307
First off you need to get the API for sleep, which is:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

then just use

Sleep 1000

instead of

Call Sleep(2000)
0
 

Expert Comment

by:excitebite
ID: 9782316
make the 1000 2000.

and remember, 1000ms = 1s... so 2000 is a 2 second wait :P
0
 

Expert Comment

by:enari
ID: 9782446
Hi!

One large point stands out in your code ..

I don't see anywhere where you incrrament NumClick.
If numclick is declared outside the procedure, such as a public variable, it should work fine.
If numclick is only used inside Command3_click then you need to declare it as "Static" so that the variable keeps it's value between clicks.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MsgBox 2 61
VBA/SQL - Connect to SQL server and pull data 4 135
using web browser with BING 40 136
Automatic Email Reminder 4 75
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question