The size of the usable area in a form is provided by the
InsideHeight and InsideWidth, not the form Width. The
InsideHeight includes the form's header and footer sections,
so if those exist, they must be subtracted from InsideHeight
to determine the height of the detail section.
To dynamically resize/reposition controls as a user drags
the form's border, you need to use the form's Resize event.
However, the mouse movement triggers the event fairly
rapidly. This means that you should not try to execute too
much (?) code so it can finish before the next event occurs.
If multiple Resize events occur before the code finishes,
the form adjustments will be jerky and may go berserk.
I don't see any code where you use the size of the form, but
I think you probably need somthing along these lines at the
beginning or your procedure:
If Me.InsideHeight < Me.InsideWidth Then
Me.Clock.Height = Me.InsideHeight
Else
Me.Clock.Height = Me.InsideWidth
End If
Me.Clock.Width = Me.Clock.Height
I am not about to analyze your math, but I did notice that
you are processing some of the array elements twice.
I also see that you are using CDbl(Right(Time$, 2)) multiple
times. You should do those kinds of calculations once:
Sec6 = DatePart("s",Time) * 6
If Sec6 >= 270 And Sec6 < 360 Then
Also, simple calculations such as 3.14159 / 180 should be
done at compile time by using constant declarations:
Const PI As Double = 3.14159
Const PI180 As Double = PI / 180
--
Marsh
MVP [MS Access]
The hands are lines that The size and locations are based on the forms width.
I didn't know you could use an inside height. Here is the code that
arranges the numbers and sets the second hand.
Dim radAngle As Double, sl As Double, angle As Double, hwidth As Double,
hheight As Double
Dim sectop As Double, sleft As Double, mtop As Double, mleft As Double, htop
As Double, hleft As Double
Dim ml As Double, hl As Double, x As Double, nangle As Double
Dim facearray
facearray = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
sl = Forms!clock.Width / 5 / 1440
sectop = Forms!clock.Width / 5 / 1440
sleft = Forms!clock.Width / 2 / 1440
For x = 0 To 13
If x <= 4 Then
nangle = (CDbl(facearray(x) + 1) * 30)
Me.Controls(facearray(x)).Top = (Abs(sl - ((sl * Sin(nangle *
3.14159 / 180)))) + sectop) * 1440
Me.Controls(facearray(x)).Left = (sleft * 1440) + (Abs((sl *
Cos(nangle * 3.14159 / 180))) * 1440)
Me.Controls(facearray(x)).Visible = 1
End If
If x > 3 And x <= 7 Then
nangle = (CDbl(facearray(x) + 1) * 30)
Me.Controls(facearray(x)).Top = ((sectop + sl) * 1440) + (Abs((sl *
Sin(nangle * 3.14159 / 180))) * 1440)
Me.Controls(facearray(x)).Left = (sleft * 1440) + (Abs((sl *
Cos(nangle * 3.14159 / 180))) * 1440)
End If
If x > 6 And x <= 10 Then
nangle = (CDbl(facearray(x) + 1) * 30)
Me.Controls(facearray(x)).Top = ((sectop + sl) * 1440) + (Abs((sl *
Sin(nangle * 3.14159 / 180))) * 1440)
Me.Controls(facearray(x)).Left = (sleft * 1440) - (Abs((sl *
Cos(nangle * 3.14159 / 180))) * 1440)
End If
If x > 9 And x <= 14 Then
nangle = (CDbl(facearray(x) + 1) * 30)
Me.Controls(facearray(x)).Top = (Abs(sl - ((sl * Sin(nangle *
3.14159 / 180)))) + sectop) * 1440
Me.Controls(facearray(x)).Left = (sleft * 1440) - (Abs((sl *
Cos(nangle * 3.14159 / 180))) * 1440)
End If
Next x
radAngle = CDbl(Right(Time$, 2)) * 6
angle = radAngle * 3.14159 / 180
hwidth = sl * Cos(angle)
hheight = sl * Sin(angle)
'programming for second hand
If CDbl(Right(Time$, 2)) * 6 < 90 Then
sangle = (90 - (CDbl(Right(Time$, 2)) * 6))
Me!second.Left = sleft * 1440
Me!second.LineSlant = 1
Me!second.Width = (Abs((sl * Cos(sangle * 3.14159 / 180))) * 1440)
Me!second.Height = (Abs((sl * Sin(sangle * 3.14159 / 180))) *
1440)
Me!second.Top = (Abs(sl - ((sl * Sin(sangle * 3.14159 / 180))))
+ sectop) * 1440
End If
If CDbl(Right(Time$, 2)) * 6 >= 90 And CDbl(Right(Time$, 2)) * 6 < 180
Then
sangle = ((CDbl(Right(Time$, 2)) * 6) - 90)
Me!second.Left = sleft * 1440
Me!second.LineSlant = 0
Me!second.Width = (Abs((sl * Cos(sangle * 3.14159 / 180))) * 1440)
Me!second.Height = (Abs((sl * Sin(sangle * 3.14159 / 180))) *
1440)
Me!second.Top = (sectop + sl) * 1440
End If
If CDbl(Right(Time$, 2)) * 6 >= 180 And CDbl(Right(Time$, 2)) * 6 <
270 Then
sangle = (90 - (CDbl(Right(Time$, 2)) * 6))
Me!second.LineSlant = 1
Me!second.Left = (sleft - (Abs((sl * Cos(sangle * 3.14159 /
180))))) * 1440
Me!second.Top = (sectop + sl) * 1440
Me!second.Width = (Abs((sl * Cos(sangle * 3.14159 / 180))) * 1440)
Me!second.Height = (Abs((sl * Sin(sangle * 3.14159 / 180))) *
1440)
End If
If CDbl(Right(Time$, 2)) * 6 >= 270 And CDbl(Right(Time$, 2)) * 6 < 360
Then
sangle = (CDbl(Right(Time$, 2)) * 6) - 270
Me!second.LineSlant = 0
Me!second.Left = (sleft - (Abs((sl * Cos(sangle * 3.14159 /
180))))) * 1440
Me!second.Top = (sectop + sl - (Abs((sl * Sin(sangle * 3.14159 /
180))))) * 1440
Me!second.Width = (Abs((sl * Cos(sangle * 3.14159 / 180))) * 1440)
Me!second.Height = (Abs((sl * Sin(sangle * 3.14159 / 180))) *
1440)
End If