lunes, enero 21, 2013

Animaciones en VBA


Como crear una animación en Excel,Access, etc:
Se puede usar application.wait para realizar la espera, pero esto nos limita a un mínimo de un segundo entre imagenes por lo que la animación no será creible.
application.Wait (Now + TimeValue("0:00:01"))

Mejor, se puede usar la clase Timer ya que cuenta el tiempo en milisegundos y se puede crear un efecto mas fluido.
Aquí mi código que redimensiona un formulario con un efecto deslizamiento.

Option Explicit

Private Sub showAdminOptions()
   Dim x As Single
   Dim i As Integer
   If (Me.Height = 267) Then ' Is hidden
      For i = 1 To 9
         Me.Height = Me.Height + i
         x = Timer
         While Timer - x < 0.05
            DoEvents
         Wend
      Next i
   End If
End Sub

Private Sub hideAdminOptions()
   Dim x As Single
   Dim i As Integer
   If (Me.Height = 312) Then ' Is shown
      For i = 1 To 9
         Me.Height = Me.Height - i
         x = Timer
         While Timer - x < 0.05
            DoEvents
         Wend
      Next i
   End If
End Sub


No hay comentarios: