Вы находитесь на странице: 1из 13

Ejemplo 1

Colocar
un
control Shape redondo,
y
3
controles
llamados Horas, Minutos y Segundos como la siguiente imagen

Line

Tambin colocar un control timer llamado Timer1 con el Interval en 1000

Cdigo:
Texto planoImprimir
1. Private Sub Timer1_Timer()
2.
Const Radianes = 3.1415927 / 180
3.
4.
Horas.X2 = 2500 + Sin(Hour(Now) * 30 * Radianes) * 1000
5.
Horas.Y2 = 2500 - Cos(Hour(Now) * 30 * Radianes) * 1000
6.
7.
Minutos.X2 = 2500 + Sin(Minute(Now) * 6 * Radianes) * 1500
8.
Minutos.Y2 = 2500 - Cos(Minute(Now) * 6 * Radianes) * 1500
9.
10.
Segundos.X2 = 2500 + Sin(Second(Now) * 6 * 3.1415927 / 180) * 2000
11.
Segundos.Y2 = 2500 - Cos(Second(Now) * 6 * 3.1415927 / 180) * 2000
12. End Sub

Ejemplo 2
Este es otro ejemplo de un reloj anlogico. Colocar en el formulario un control
Picturebox donde se dibujar el reloj, y colocar un Timer

Cdigo fuente en el Form 1


Texto planoImprimir
1. Option Explicit
2.
3. Private Const PI = 3.14159265
4.
5. Private Sub Reloj()
6. Static last_time As Date
7.
8. Dim cx As Single
9. Dim cy As Single
10. Dim num As Single
11. Dim radius As Single
12. Dim theta As Single
13.
14.
If last_time = Now Then Exit Sub
15.
16.
last_time = Now
17.
Picture1.Cls
18.
Picture1.ForeColor = vbBlue
19.
cx = Picture1.ScaleWidth / 2
20.
cy = Picture1.ScaleHeight / 2
21.
22.
' Horas
23.
num = 5 * (DatePart("h", last_time) + DatePart("n", last_time) / _
24.
60 + DatePart("s", last_time) / 3600)
25.
theta = MinutesToRadians(num)
26.
radius = Picture1.ScaleWidth * 0.3
27.
Picture1.DrawWidth = 3
28.
Picture1.Line (cx, cy)-Step(radius * Cos(theta), radius * Sin(theta))
29.
30.
' Los Minutos
31.
num = DatePart("n", last_time)
32.
theta = MinutesToRadians(num)
33.
radius = Picture1.ScaleWidth * 0.3
34.
Picture1.DrawWidth = 2
35.
Picture1.Line (cx, cy)-Step(radius * Cos(theta), radius * Sin(theta))
36.
37.
' Los segundos
38.
num = DatePart("s", last_time)

39.
40.
41.
42.

theta = MinutesToRadians(num)
radius = Picture1.ScaleWidth * 0.4
Picture1.DrawWidth = 1
Picture1.Line (cx, cy)-Step(radius * Cos(theta), radius * Sin(theta))
43. End Sub
44. Private Sub DrawFace()
45. Dim r1 As Single
46. Dim r2 As Single
47. Dim r3 As Single
48. Dim cx As Single
49. Dim cy As Single
50. Dim i As Integer
51. Dim theta As Single
52.
53.
Picture1.AutoRedraw = True
54.
Picture1.ForeColor = vbRed
55.
cx = Picture1.ScaleWidth / 2
56.
cy = Picture1.ScaleHeight / 2
57.
r1 = Picture1.ScaleWidth * 0.45
58.
r2 = Picture1.ScaleWidth * 0.4
59.
r3 = Picture1.ScaleWidth * 0.35
60.
61.
For i = 1 To 60
62.
theta = MinutesToRadians(i)
63.
If i Mod 5 = 0 Then
64.
Picture1.Line (cx + r1 * Cos(theta), _
65.
cy + r1 * Sin(theta))(cx + r3 * Cos(theta), cy + r3 * Sin(theta))
66.
Else
67.
Picture1.Line (cx + r1 * Cos(theta), _
68.
cy + r1 * Sin(theta))(cx + r2 * Cos(theta), cy + r2 * Sin(theta))
69.
End If
70.
Next i
71.
72.
Picture1.Picture = Picture1.Image
73. End Sub
74. Private Function MinutesToRadians(ByVal num As Single) As Single
75.
MinutesToRadians = (15 - num) * 2 * PI / 60
76. End Function
77.
78.
79. Private Sub Form_Load()
80.
DrawFace
81.
Timer1.Interval = 1000
82.
Picture1.BorderStyle = 0
83. End Sub
84.
85. Private Sub Picture1_Paint()
86.
Reloj
87. End Sub
88.
89.
90. Private Sub timer1_Timer()
91.
' actualiza
92.
Reloj
93. End Sub

Ejemplo 1

Este es un un cronmetro en vb realizado y enviado por Helmuth Campos:


Contador para cronometrar un tiempo, realizado con un control Timer y la funcin
Format de visual basic

Descargar proyecto

Colocar en un formulario los siguientes controles :

Un Timer llamado Timer1

Un label llamado lblCronometro

Tres CommandButton : ( cmdIniciar, cmdDetener y cmdSalir)

Cdigo fuente en el Formulario


Texto planoImprimir
1. Option Explicit
2.
3. Dim I As Long
'Contador.
4. Dim Tiempo As String 'Tiempo total transcurrido.
5.
6. Private Sub cmdDetener_Click()
7.
Timer1.Interval = 0
8. End Sub
9.
10. Private Sub cmdIniciar_Click()
11.
I = 0 'Inicializar el contador.
12.
Timer1.Interval = 0
'Detener el cronometro
13.
lblCronometro.Caption = "" 'Limpiar la etiqueta
14.
Timer1.Interval = 1
'Iniciar el cronometro
15. End Sub
16.
17. Private Sub cmdSalir_Click()
18.
End
19. End Sub
20.
21. Private Sub Form_Load()
22.
cmdIniciar.Caption = "Iniciar"
23.
cmdDetener.Caption = "Detener"
24.
cmdSalir.Caption = "Salir"
25. End Sub
26.

27. Private Sub Form_Resize()


28.
On Error Resume Next
29.
'Centra el formulario completamente
30.
Move (Screen.Width - Width) \ 29, (Screen.Height - Height) \ 29
31.
32. End Sub
33.
34. Private Sub Form_Unload(Cancel As Integer)
35.
End
36. End Sub
37.
38. Private Sub Timer1_Timer()
39.
I = I + 1
40.
Tiempo = Format(Int(I / 36000) Mod 24, "00") & ":" & _
41.
Format(Int(I / 600) Mod 60, "00") & ":" & _
42.
Format(Int(I / 10) Mod 60, "00") & ":" & _
43.
Format(I Mod 10, "00")
44.
lblCronometro.Caption = Tiempo
45. End Sub

Ejemplo 2
Otro ejemplo enviado por Ivo Scavuzzo de un cronmetro con cuenta regresiva :

Colocar en el form : Un commandbutton llamado CmdIniciar,


LblTimeSession, otro label lblCRegresiva, y un timer llamado Timer1
Texto planoImprimir
1. Option Explicit
2.
3. Private Sub cmdIniciar_Click()
4. If cmdIniciar.Caption = "Iniciar" Then
5.
Timer1.Enabled = True
6.
cmdIniciar.Caption = "Detener"
7. Else
8.
Timer1.Enabled = False
9.
cmdIniciar.Caption = "Iniciar"
10. End If
11. End Sub

un

Label

12.
13. Private Sub Form_Load()
14.
cmdIniciar.Caption = "Iniciar"
15.
Timer1.Interval = 1000
16. End Sub
17.
18. Private Sub Timer1_Timer()
19.
LblTimeSession.Caption = Format(CDate(LblTimeSession.Caption) + _
20.
CDate("00:00:01"), "Hh:mm:ss")
21.
22.
lblCRegresiva.Caption = Format(CDate(lblCRegresiva.Caption) - _
23.
CDate("00:00:01"), "Hh:mm:ss")
24.
If lblCRegresiva.Caption < CDate("00:00:00") Then
25.
lblCRegresiva.Caption = "01:00:00"
26.
End If
27.
28. End Sub

Programa 4 - Algoritmo que indique el tiempo simulado en un reloj digital


Programa 4 - Algoritmo que indique el tiempo simulado en un reloj digital

Este programa cost algo de trabajo realizarlo. A continuacin les muestro 2 versiones que mis
compaeros elaboraron las cuales realizaban diferentes funciones, aunque a simple viste no
pareciera de esta manera.

Planteamiento del problema: Crear un algoritmo que indique el tiempo simulado en un


reloj digital.

Versin 1

Algoritmo / Pseudocdigo:

Diagrama de Flujo

Versin 2

Algoritmo / Pseudocdigo:

Diagrama de Flujo

Versin 3
- Algoritmo / Pseudocdigo:

- Diagrama de Flujo

Prueba de Escritorio
Las Pruebas de Escritorio de las 3 versiones del algoritmo se encuentran en el siguiente link
para mayor comodidad el visualizarlas:
Pruebas de Escritorio de las 3V del Algoritmo
Publicado por Michel Vellve en 22:28

Vellve Montoya Michel /


P.E Reloj Digital V1 /
Secuencia 2NV50
Variables
Pant hor minu segun
alla as tos
dos
1
1
1
1
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30

Vellve Montoya Michel /


P.E Reloj Digital V2 /
Secuencia 2NV50

Vellve Montoya Michel / P.E


Reloj Digital FUNCIONAL /
Secuencia 2NV50

Variables
Pantalla

min seg

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
0
1
2
3
4
5
6
7

Variables
Pantalla

x y z a

0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
0:00:10
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17
0:00:18
0:00:19
0:00:20
0:00:21
0:00:22
0:00:23
0:00:24
0:00:25
0:00:26
0:00:27
0:00:28
0:00:29
0:00:30
0:00:31

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
3
3

0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

0:00:32
0:00:33
0:00:34
0:00:35
0:00:36
0:00:37
0:00:38
0:00:39
0:00:40
0:00:41
0:00:42
0:00:43
0:00:44
0:00:45
0:00:46
0:00:47
0:00:48
0:00:49
0:00:50
0:00:51
0:00:52
0:00:53
0:00:54
0:00:55
0:00:56
0:00:57
0:00:58
0:00:59
0:01:00
0:01:01
0:01:02
0:01:03
0:01:04
0:01:05
0:01:06
0:01:07
0:01:08
0:01:09
0:01:10
0:01:11
0:01:12
0:01:13
0:01:14
0:01:15

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1

2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2

52
53
54
55
56
57
58
59
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

0:01:16

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0 1 1
0:01:17
0 1 1
0:01:18
0 1 1
0:01:19
0 1 1
0:01:20
0 1 2
0:01:21
0 1 2
0:01:22
0 1 2
0:01:23
0 1 2
0:01:24
0 1 2
0:01:25
0 1 2
0:01:26
0 1 2
0:01:27
0 1 2
0:01:28
0 1 2
0:01:29
0 1 2
0:01:30
0 1 3
Avanzando un poco el
tiempo

6
7
8
9
0
1
2
3
4
5
6
7
8
9
0

1:00:00
1:00:01
1:00:02
1:00:03
1:00:04
1:00:05
1:00:06
1:00:07
1:00:08
1:00:09
1:00:10
1:00:11
1:00:12
1:00:13
1:00:14
1:00:15
1:00:16
1:00:17
1:00:18
1:00:19
1:00:20
1:00:21
1:00:22
1:00:23
1:00:24
1:00:25
1:00:26

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
23:59:59

1:00:27
1:00:28
1:00:29
1:00:30

0
0
0
0

1
1
1
1

0
0
0
0

0
0
0
0

2
2
2
3

7
8
9
0

Вам также может понравиться