hola a todos necesito ayuda con lo siguiente
Estoy haciendo un programa que necesita repetir una misma instruccion con un retardo minimo, tal que el control timer no me sirve.
El codigo que estoy usando en este momento no me convence del todo
For TT = 1 To VARIABLE
For T = 1 To 10000: Next T
Next TT
Este codigo tiene la contra de aumentar conciderablemente el uso del CPU.
Por lo tanto cuando necesito mayor retardo es cuando mas esta exigido, y tendria que estar menos exigido en realidad. El programa se vuelve muy inestable, aveces aparece como (No responde) y luego retoma...
Ya probe pon el control Sleep y tampoco me dio resultado...
Agradeceria mucho que me ayuden con esto, ya que al no tener un codigo claro para este motivo me afecta el funcionamiento de todo el programa...
Saludos IvanUgu
CitarYa probe pon el control Sleep y tampoco me dio resultado...
esta seguro de que lo probaste bien el sleep por que yo uso sleep especialmente para retardos ::)
describe que pasa con el sleep
Usa el DoEvents...
Saludos...
Gracias por responder... ahora voy a probar bien con el Sleep y despues les cuento como me fue
si no te da con el sleep prueba con static timer del control timer
puedes usar:
un timer
un bucle
Sleep
GetTickCount
:P
Se puede hacer una pausa inferior a 16 milisegundos ???
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Timer1.Interval = 100
Command1.Caption = "GetTickCount"
Command2.Caption = "Sleep"
End Sub
Private Sub Form_DblClick()
Me.Cls
End Sub
Private Sub Command1_Click()
Me.Print GetTickCount
x = GetTickCount: While GetTickCount < x + 15: DoEvents: Wend
Me.Print GetTickCount
End Sub
Private Sub Command2_Click()
Me.Print GetTickCount
Sleep (1)
Me.Print GetTickCount
End Sub
mmm si(?)
modificando ese codigo q pusiste... el del gettickcount xD
no lo viste mucho no?
1 y 15 me da lo mismo , no puedo bajar los 16 milisegundos
Private Sub Command1_Click()
Me.Print GetTickCount
x = GetTickCount: While GetTickCount < x + 15: DoEvents: Wend
Me.Print GetTickCount
Me.Print GetTickCount
x = GetTickCount: While GetTickCount < x + 1: DoEvents: Wend
Me.Print GetTickCount
End Sub
No pobraste mucho no ???
a mi no me dio lo mismo cuando lo probe :S
dependera de la velocidad del procesador de tu computadora...
Probé con un celeron D 2.4, ahora voy a prubar con un PIII y un Dual Core.
yo tambien tengo ese problema mira el code
Private Sub Command2_Click()
Secuencia:
If Me.Caption <> 100 Then
Me.Caption = Me.Caption + 1
Sleep (0.5)
GoTo Secuencia
End If
End Sub
si cambio el Sleep (0.6) ya va muchisimo mas lento, pruevenlo...
Private Sub Command2_Click()
Secuencia:
If Me.Caption <> 100 Then
Me.Caption = Me.Caption + 1
Sleep (0.6)
GoTo Secuencia
End If
End Sub
Lo que necesito es dar pocos milisegundos y con Sleep me parece que no se puede...
QueryPerformanceCounter
Probé con un dual core E-5200 y lo mismo, no lo pude bajar, no creo que sea problema de micro, voy a probar con tu code IvanUgu y con el de Cobein. Saludos
Tampoco puedo con QueryPerformanceCounter (es 0 o 16 Milisegundos)
Private Type LARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.Print GetTickCount
Dim T As Long, liFrequency As LARGE_INTEGER, liStart As LARGE_INTEGER, liStop As LARGE_INTEGER
Dim cuFrequency As Currency, cuStart As Currency, cuStop As Currency
'Retrieve the frequency of the performance counter
If QueryPerformanceFrequency(liFrequency) = 0 Then
MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
Else
'convert the large integer to currency
cuFrequency = LargeIntToCurrency(liFrequency)
'retrieve tick count
QueryPerformanceCounter liStart
'do something
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
For T = 0 To 20000
'For T = 0 To 100000
DoEvents
Next T
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
'retrieve tick count
QueryPerformanceCounter liStop
'convert large integers to currency's
cuStart = LargeIntToCurrency(liStart)
cuStop = LargeIntToCurrency(liStop)
'calculate how many seconds passed, and show the result
Me.Print CStr((cuStop - cuStart) / cuFrequency)
Me.Print GetTickCount
End If
End Sub
Private Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency
'copy 8 bytes from the large integer to an ampty currency
CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
'adjust it
LargeIntToCurrency = LargeIntToCurrency * 10000
End Function
Private Sub Form_Paint()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.Print GetTickCount
Dim T As Long, liFrequency As LARGE_INTEGER, liStart As LARGE_INTEGER, liStop As LARGE_INTEGER
Dim cuFrequency As Currency, cuStart As Currency, cuStop As Currency
'Retrieve the frequency of the performance counter
If QueryPerformanceFrequency(liFrequency) = 0 Then
MsgBox "Your hardware doesn't support a high-resolution performance counter!", vbInformation
Else
'convert the large integer to currency
cuFrequency = LargeIntToCurrency(liFrequency)
'retrieve tick count
QueryPerformanceCounter liStart
'do something
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
For T = 0 To 20000
'For T = 0 To 100000
DoEvents
Next T
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
'*****************************************************
'retrieve tick count
QueryPerformanceCounter liStop
'convert large integers to currency's
cuStart = LargeIntToCurrency(liStart)
cuStop = LargeIntToCurrency(liStop)
'calculate how many seconds passed, and show the result
Me.Print CStr((cuStop - cuStart) / cuFrequency)
Me.Print GetTickCount
End If
End Sub
Tal vez con una "ayudita" de Cobein resultaría
A mi me pasa lo mismo no puedo hacer menos de 16ms :xD