Microsoft Office Tutorials and References
In Depth Information
Animating a Label
The code that’s attached to the button is as follows:
Dim Stopped As Boolean
Private Sub StartStopButton_Click()
Dim Low As Double, Hi As Double
If StartStopButton.Caption = “Start” Then
‘ validate low and hi values
If Not IsNumeric(TextBox1.Text) Then
MsgBox “Non-numeric starting value.”, vbInformation
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Exit Sub
End If
If Not IsNumeric(TextBox2.Text) Then
MsgBox “Non-numeric ending value.”, vbInformation
With TextBox2
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Exit Sub
End If
‘ Make sure they aren’t in the wrong order
Low = Application.Min(Val(TextBox1.Text), Val(TextBox2.Text))
Hi = Application.Max(Val(TextBox1.Text), Val(TextBox2.Text))
‘ Adjust font size, if necessary
Select Case Application.Max(Len(TextBox1.Text), Len(TextBox2.Text))
Case Is < 5: Label1.Font.Size = 72
Case 5: Label1.Font.Size = 60
Case 6: Label1.Font.Size = 48
Case Else: Label1.Font.Size = 36
End Select
StartStopButton.Caption = “Stop”
Stopped = False
Randomize
Do Until Stopped
Label1.Caption = Int((Hi - Low + 1) * Rnd + Low)
DoEvents ‘ Causes the animation
Loop
Else
Stopped = True
 
Search JabSto ::




Custom Search