Projet VB horloge sept segments

Résolu
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011 - 12 oct. 2011 à 20:02
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 - 31 oct. 2011 à 16:51
Bonjour à tous.

Je suis nouveau sur ce forum car je viens de me mettre au VB. La raison ? Je suis rentrée a l'UTC et j'ai choisit une Unité de d’enseignement (UV) qui est micro-ordinateurs et application (ça parle de VB, intéressant et très utile en entreprise).
Je n'ai jamais fais de VB et il n'y avait pas besoin de prérequis.

J'ai un projet à réaliser un programme affichant une grande horloge à cristaux liquides donnant les heures les minutes et les secondes. L'affichage doit être du type cristaux liquides à 7 segments.
Vous devez afficher les segments individuellement de la façon suivante:
Un segment allumé doit être affiché en noir.
Un segment éteint doit être affiché en grisé (ou d'une couleur peu différente du fond de la fenêtre).
On doit avoir la possibilité d'afficher une fenêtre de remise à l'heure.
Cette horloge devra être dotée de 3 alarmes visuelles réglables et désactivables que l'on pourra enregistrer et sauvegarder dans un fichier. Celles-ci seront chargées, si elles existent, au démarrage du programme.

Cependant, je ne voix vraiment pas comment et par ou commencer sachant que je n'y connais rien. J'ai analyser des projets similaires sur ce site mais ils sont trop compliqué et il y a beaucoup de code.

Pourriez vous m'aidez svp?

19 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
12 oct. 2011 à 23:53
Salut

Oui, la programmation s'apprend et il faut s'y mettre.
Il y a la technique du copier-coller du code trouvé par-ci par-là et qui oblige à essayer de comprendre un minimum, et il y a la technique qui consiste à commencer par le début - les bases - et faire des essais perso sur des sujets simples : les types de variables, le découpage des chaines de caractère, les opérations mathématiques simples, les composants ...

Première chose, faire des recherches parmi les sources du site en .Net avec ce simple mot : "segment".

Pour commencer, par exemple, crée une fonction à laquelle tu fourniras un chiffre (0 à 9) et qui te renverra un tableau de 7 Booléen, un pour chaque segment.
Avec un peu d'observation et de logique, c'est facile à faire.

Ensuite, tu lis l'heure actuelle et tu envoies à ta fonction chaque chiffre composant l'heure. Elle te retourne les 7 booléens et tu animes tes segments.
Les fonctions de base de manipulation de chaine devrait suffire : à maitriser en premier.

En ce qui concernent les alarmes, suffira de jongler avec les fonctions adaptées aux calculs de date, genre DateAdd, DateDiff.

Ces sujets ne sont que des points de départ.
Tu trouveras des exemples parmi les sources du site, mais c'est à toi de les lire et de les comprendre afin de, peut-être, t'en servir, du moins t'en inspirer.

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
3
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
14 oct. 2011 à 10:50
Bonjour,

Je le verrais un peu de façon différente, tu mets dix picturBox invisibles ou dedans tu écris chacun des tes chiffres avec les segmebts visibles et invisibles (tu fais ça en dessin avec Paint), donc après tu l'as deviné, tu mets dix pictureBox visibles pour l'heure, et selon l'heure tu charge dans tes six picturbix HH MN SS une des dix images qui correspondent.

Pour la remise à l'heure, moi je pendrais des comboBox, pas toujours d'utilisation pratique mais très encadrants (HH MN SS) + <ok> ... ou un bouton qui lit l'heure du PC, c'est plus simple.

Poiur ls alarmes, sur le principe des comboBox de la remise à l'heure, avec ensuite un timer qui tourne dès la première alarme et s'arr^te quand il n'y a plus d'alarme, les alarmes étant gérées par des variable dans la procédure du timer.

C'est quoi l'UTC ?

C'est pas difficile ce que tu veux faire, mais sans connaître VB, ça va être difficile car tu va planter sans cesse sur des détails, quand ce n'est pas l'éditeur, faudra revenir ici...

Sinon, encore un piste, pour des segments, tu mets de Label et tu allume ou éteint selon les besoins, avec un DoEvents si besoin, si la musique va trop vite et qu'il n'a ps le temps de changer de couleur...

@+, bye, Joe.
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
15 oct. 2011 à 12:13
Bonjour, suite,

J'ai fait ton horloge pour le sport, je l'ai déposé en tant que code source vbNet, ici :

http://www.vbfrance.com/codes/HORLOGE-DIODE-AVEC-ALARMES-REMISE-HEURE_53680.aspx

Tapez le texte de l'url ici.

Cordialement.

Joe.
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
16 oct. 2011 à 22:09
Salut
tiens une class et un form
Public Class Classdigit 
    Private digitlength As Integer
    Private heightbox As Integer
    Private widthbox As Integer
    Private brushseg As System.Drawing.Brush
    Private listbooleansegment As New List(Of Boolean)
    Private Sub segment(ByVal GR As System.Drawing.Graphics, ByVal booleanvector As List(Of Boolean))
        Dim lengthsegment As Integer
        Dim vertex(6) As Point
        lengthsegment = digitlength
        'horizontal up
        vertex(0).X = 8
        vertex(0).Y = 2

        vertex(1).X = vertex(0).X + lengthsegment - 2
        vertex(1).Y = vertex(0).Y
        vertex(2).X = vertex(1).X + 2

        vertex(2).Y = vertex(1).Y + 2
        vertex(3).X = vertex(1).X

        vertex(3).Y = vertex(2).Y + 2
        vertex(4).X = vertex(0).X
        vertex(4).Y = vertex(3).Y
        vertex(5).X = vertex(0).X - 2
        vertex(5).Y = vertex(4).Y - 2
        vertex(6) = vertex(0)
        If booleanvector(0) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If


        'horizontal middle
        vertex(0).X = 8
        vertex(0).Y = lengthsegment
        vertex(1).X = vertex(0).X + lengthsegment - 2
        vertex(1).Y = vertex(0).Y
        vertex(2).X = vertex(1).X + 2
        vertex(2).Y = vertex(1).Y + 2
        vertex(3).X = vertex(1).X
        vertex(3).Y = vertex(2).Y + 2
        vertex(4).X = vertex(0).X
        vertex(4).Y = vertex(3).Y
        vertex(5).X = vertex(0).X - 2
        vertex(5).Y = vertex(4).Y - 2
        vertex(6) = vertex(0)
        If booleanvector(1) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If

        'horizontal bottom
        vertex(0).X = 8
        vertex(0).Y = lengthsegment * 2
        vertex(1).X = vertex(0).X + lengthsegment - 2
        vertex(1).Y = vertex(0).Y
        vertex(2).X = vertex(1).X + 2
        vertex(2).Y = vertex(1).Y + 2
        vertex(3).X = vertex(1).X
        vertex(3).Y = vertex(2).Y + 2
        vertex(4).X = vertex(0).X
        vertex(4).Y = vertex(3).Y
        heightbox = vertex(4).Y + 6
        vertex(5).X = vertex(0).X - 2
        vertex(5).Y = vertex(4).Y - 2
        vertex(6) = vertex(0)
        If booleanvector(2) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If

        'vertical top left
        vertex(0).X = 8 - 6
        vertex(0).Y = 5
        vertex(1).X = vertex(0).X + 2
        vertex(1).Y = vertex(0).Y - 2
        vertex(2).X = vertex(1).X + 2
        vertex(2).Y = vertex(1).Y + 2
        vertex(3).X = vertex(2).X
        vertex(3).Y = vertex(2).Y + lengthsegment - 5
        vertex(4).X = vertex(1).X
        vertex(4).Y = vertex(3).Y + 2
        vertex(5).X = vertex(0).X
        vertex(5).Y = vertex(3).Y
        vertex(6) = vertex(0)
        If booleanvector(3) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If

        'vertical top right
        vertex(0).X = 8 + lengthsegment
        vertex(0).Y = 5
        vertex(1).X = vertex(0).X + 2
        vertex(1).Y = vertex(0).Y - 2
        vertex(2).X = vertex(1).X + 2
        vertex(2).Y = vertex(1).Y + 2

        widthbox = vertex(2).X + 6
        vertex(3).X = vertex(2).X
        vertex(3).Y = vertex(2).Y + lengthsegment - 5
        vertex(4).X = vertex(1).X
        vertex(4).Y = vertex(3).Y + 2
        vertex(5).X = vertex(0).X
        vertex(5).Y = vertex(3).Y
        vertex(6) = vertex(0)
        If booleanvector(4) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If

        'vertical bottom left
        vertex(0).X = 8 - 6
        vertex(0).Y = lengthsegment + 5
        vertex(1).X = vertex(0).X + 2
        vertex(1).Y = vertex(0).Y - 2
        vertex(2).X = vertex(1).X + 2
        vertex(2).Y = vertex(1).Y + 2
        vertex(3).X = vertex(2).X
        vertex(3).Y = vertex(2).Y + lengthsegment - 5
        vertex(4).X = vertex(1).X
        vertex(4).Y = vertex(3).Y + 2
        vertex(5).X = vertex(0).X
        vertex(5).Y = vertex(3).Y
        vertex(6) = vertex(0)
        If booleanvector(5) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If

        'vertical bottom right
        vertex(0).X = 8 + lengthsegment
        vertex(0).Y = lengthsegment + 5
        vertex(1).X = vertex(0).X + 2
        vertex(1).Y = vertex(0).Y - 2
        vertex(2).X = vertex(1).X + 2
        vertex(2).Y = vertex(1).Y + 2
        vertex(3).X = vertex(2).X
        vertex(3).Y = vertex(2).Y + lengthsegment - 5
        vertex(4).X = vertex(1).X
        vertex(4).Y = vertex(3).Y + 2
        vertex(5).X = vertex(0).X
        vertex(5).Y = vertex(3).Y
        vertex(6) = vertex(0)
        If booleanvector(6) = True Then
            GR.FillPolygon(brushseg, vertex)
        Else
            GR.FillPolygon(Brushes.Gray, vertex)
        End If
    End Sub

    Public Sub New(ByVal segemtlength As Integer, ByVal brushsegment As System.Drawing.Brush)
        digitlength = segemtlength
        brushseg = brushsegment
    End Sub
    Private Function UpdateBooleanVector(ByVal digit As Integer) As List(Of Boolean)
        Dim sevensegbool As New List(Of Boolean)
        
        Select Case digit
            Case 0
                For iter = 0 To 6
                    If iter <> 1 Then
                        sevensegbool.Add(True)
                    Else
                        sevensegbool.Add(False)
                    End If

                Next
               
            Case 1
                For iter = 0 To 6
                    If iter <> 4 And iter <> 6 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next

            Case 2
                For iter = 0 To 6
                    If iter 3 Or iter 6 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
            Case 3
                For iter = 0 To 6
                    If iter 3 Or iter 5 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
            Case 4
                For iter = 0 To 6
                    If iter 0 Or iter 2 Or iter = 5 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
            Case 5
                For iter = 0 To 6
                    If iter 4 Or iter 5 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
            Case 6
                For iter = 0 To 6
                    If iter = 4 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
            Case 7
                For iter = 0 To 6
                    If iter <> 4 And iter <> 6 And iter <> 0 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
            Case 8
                For iter = 0 To 6
                    sevensegbool.Add(True)
                Next

            Case 9
                For iter = 0 To 6
                    If iter = 5 Then
                        sevensegbool.Add(False)
                    Else
                        sevensegbool.Add(True)
                    End If

                Next
        End Select

        Return sevensegbool
    End Function
    Public Sub DrawDigit(ByVal gr As System.Drawing.Graphics, ByVal digit As Integer)
        listbooleansegment = UpdateBooleanVector(digit)
        segment(gr, listbooleansegment)
    End Sub
    Public Function GetHeightBox() As Integer
        Return heightbox
    End Function
    Public Function GetwidthBox() As Integer
        Return widthbox
    End Function
End Class

Public Class Form1
    Private digitunithourobj As Classdigit
    Private digittenhourobj As Classdigit
    Private digitunitminobj As Classdigit
    Private digittenminobj As Classdigit
    Private digitunitsecobj As Classdigit
    Private digittensecobj As Classdigit

    Private hour As Integer
    Private min As Integer
    Private sec As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim withdigit As Integer = 24
        Dim brushseg As System.Drawing.Brush = Brushes.Red
        digitunithourobj = New Classdigit(withdigit, brushseg)
        digittenhourobj = New Classdigit(withdigit, brushseg)
        digitunitminobj = New Classdigit(withdigit, brushseg)
        digittenminobj = New Classdigit(withdigit, brushseg)
        digitunitsecobj = New Classdigit(withdigit, brushseg)
        digittensecobj = New Classdigit(withdigit, brushseg)
        Timer1.Start()
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim Now As DateTime
        
        Now = DateTime.Now
        hour = Now.Hour
        min = Now.Minute
        sec = Now.Second
        For Each element As Control In Me.Controls
            If TypeOf element Is PictureBox Then
                DirectCast(element, PictureBox).BorderStyle = BorderStyle.None
                DirectCast(element, PictureBox).BackColor = Color.Black
            End If
        Next
        tenhour.Invalidate()
        unithour.Invalidate()
        tenminutes.Invalidate()
        unitminutes.Invalidate()
        tensecond.Invalidate()
        unitsecond.Invalidate()
        unithour.Top = tenhour.Top
        tenminutes.Top = tenhour.Top
        unitminutes.Top = tenhour.Top
        tensecond.Top = tenhour.Top
        unitsecond.Top = tenhour.Top
        
        unithour.Left = tenhour.Right

        tenminutes.Left = unithour.Right + 1
        
        unitminutes.Left = tenminutes.Right

        tensecond.Left = unitminutes.Right + 1
        
        unitsecond.Left = tensecond.Right


    End Sub

    Private Sub tenhour_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles tenhour.Paint
        digittenhourobj.DrawDigit(e.Graphics, hour \ 10)
        tenhour.Width = digittenhourobj.GetwidthBox
        tenhour.Height = digittenhourobj.GetHeightBox
    End Sub

    Private Sub unithour_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles unithour.Paint
        digitunithourobj.DrawDigit(e.Graphics, hour Mod 10)
        unithour.Width = digitunithourobj.GetwidthBox
        unithour.Height = digitunithourobj.GetHeightBox
    End Sub

    Private Sub tenminutes_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles tenminutes.Paint
        digittenminobj.DrawDigit(e.Graphics, min \ 10)
        tenminutes.Width = digittenminobj.GetwidthBox
        tenminutes.Height = digittenminobj.GetHeightBox
    End Sub

    
    Private Sub unitminutes_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles unitminutes.Paint
        digitunitminobj.DrawDigit(e.Graphics, min Mod 10)
        unitminutes.Width = digitunitminobj.GetwidthBox
        unitminutes.Height = digitunitminobj.GetHeightBox
    End Sub

    Private Sub tensecond_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles tensecond.Paint
        digittensecobj.DrawDigit(e.Graphics, sec \ 10)
        tensecond.Width = digittensecobj.GetwidthBox
        tensecond.Height = digittensecobj.GetHeightBox
    End Sub

    Private Sub unitsecond_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles unitsecond.Paint
        digitunitsecobj.DrawDigit(e.Graphics, sec Mod 10)
        unitsecond.Width = digitunitsecobj.GetwidthBox
        unitsecond.Height = digitunitsecobj.GetHeightBox
    End Sub
End Class
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
17 oct. 2011 à 09:11
Bonjour,

Voici le code dans unen form avec 10 images à récupérer ici :

http://www.vbfrance.com/codes/HORLOGE-DIODE-AVEC-ALARMES-REMISE-HEURE_53680.aspx

GO

2.' horloge (form1) : vbNet 10
3.Option Explicit On
4.Public Class Form1
5.  Dim t As Integer
6.  Dim ri
7.  Dim alarme(3) As Boolean
8.  Dim Halarme(3) As String
9.  Dim alternat As Boolean
10.
11.
12.  Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
13.    Dim i As Integer
14.    Me.Left = 10
15.    Me.Top = 10
16.    Timer1.Enabled = False
17.    Timer1.Interval = 1000
18.    Timer1.Enabled = True
19.    For i = 0 To 59
20.      If i < 24 Then
21.        ComboBox1.Items.Add(Format(i, "00"))
22.        ComboBox4.Items.Add(Format(i, "00"))
23.        ComboBox7.Items.Add(Format(i, "00"))
24.        ComboBox10.Items.Add(Format(i, "00"))
25.      End If
26.      ComboBox2.Items.Add(Format(i, "00"))
27.      ComboBox3.Items.Add(Format(i, "00"))
28.      ComboBox5.Items.Add(Format(i, "00"))
29.      ComboBox6.Items.Add(Format(i, "00"))
30.      ComboBox8.Items.Add(Format(i, "00"))
31.      ComboBox9.Items.Add(Format(i, "00"))
32.      ComboBox11.Items.Add(Format(i, "00"))
33.      ComboBox12.Items.Add(Format(i, "00"))
34.    Next
35.    ComboBox1.SelectedIndex = 0
36.    ComboBox2.SelectedIndex = 0
37.    ComboBox3.SelectedIndex = 0
38.    ComboBox4.SelectedIndex = 0
39.    ComboBox5.SelectedIndex = 0
40.    ComboBox6.SelectedIndex = 0
41.    ComboBox7.SelectedIndex = 0
42.    ComboBox8.SelectedIndex = 0
43.    ComboBox9.SelectedIndex = 0
44.    ComboBox10.SelectedIndex = Now.Hour
45.    ComboBox11.SelectedIndex = Now.Minute
46.    ComboBox12.SelectedIndex = Now.Second
47.    Label1.BackColor = Color.FromArgb(225, 225, 225)
48.    Label2.BackColor = Color.FromArgb(225, 225, 225)
49.    Label3.BackColor = Color.FromArgb(225, 225, 225)
50.  End Sub
51.
52.
53.  Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
54.    t = Mid(TimeOfDay, 1, 1) ' hh:mn:ss
55.    Call quelleImage()
56.    PictureBox1.Image = ri
57.    t = Mid(TimeOfDay, 2, 1)
58.    Call quelleImage()
59.    PictureBox2.Image = ri
60.    t = Mid(TimeOfDay, 4, 1)
61.    Call quelleImage()
62.    PictureBox3.Image = ri
63.    t = Mid(TimeOfDay, 5, 1)
64.    Call quelleImage()
65.    PictureBox4.Image = ri
66.    t = Mid(TimeOfDay, 7, 1)
67.    Call quelleImage()
68.    PictureBox5.Image = ri
69.    t = Mid(TimeOfDay, 8, 1)
70.    Call quelleImage()
71.    PictureBox6.Image = ri
72.    '
73.    alternat = Not alternat
74.    If alarme(1) = True Then
75.      If TimeOfDay >= CDate(Halarme(1)) Then
76.        If alternat True Then Label1.BackColor Color.FromArgb(225, 225, 225)
77.        If alternat False Then Label1.BackColor Color.FromArgb(255, 0, 0)
78.      End If
79.    End If
80.    If alarme(2) = True Then
81.      If TimeOfDay >= CDate(Halarme(2)) Then
82.        If alternat True Then Label2.BackColor Color.FromArgb(225, 225, 225)
83.        If alternat False Then Label2.BackColor Color.FromArgb(255, 0, 0)
84.      End If
85.    End If
86.    If alarme(3) = True Then
87.      If TimeOfDay >= CDate(Halarme(3)) Then
88.        If alternat True Then Label3.BackColor Color.FromArgb(225, 225, 225)
89.        If alternat False Then Label3.BackColor Color.FromArgb(255, 0, 0)
90.      End If
91.    End If
92.  End Sub
93.
94.
95.  Sub quelleImage()
96.    Select Case t
97.      Case 0 : ri = My.Resources._0
98.      Case 1 : ri = My.Resources._1
99.      Case 2 : ri = My.Resources._2
100.      Case 3 : ri = My.Resources._3
101.      Case 4 : ri = My.Resources._4
102.      Case 5 : ri = My.Resources._5
103.      Case 6 : ri = My.Resources._6
104.      Case 7 : ri = My.Resources._7
105.      Case 8 : ri = My.Resources._8
106.      Case 9 : ri = My.Resources._9
107.    End Select
108.  End Sub
109.
110.
111.  Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
112.    alarme(1) = False
113.    Label1.BackColor = Color.FromArgb(225, 225, 225)
114.    Label1.Text = "Alarme à l'arrêt"
115.  End Sub
116.
117.  Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
118.    alarme(2) = False
119.    Label2.BackColor = Color.FromArgb(225, 225, 225)
120.    Label2.Text = "Alarme à l'arrêt"
121.  End Sub
122.
123.  Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
124.    alarme(3) = False
125.    Label3.BackColor = Color.FromArgb(225, 225, 225)
126.    Label3.Text = "Alarme à l'arrêt"
127.  End Sub
128.
129.  Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
130.    Halarme(1) = Format(ComboBox1.SelectedIndex, "00") & ":" & Format(ComboBox2.SelectedIndex, "00") & ":" & Format(ComboBox3.SelectedIndex, "00")
131.    Label1.Text "Alarme " & CDate(Halarme(1))
132.    alarme(1) = True
133.  End Sub
134.
135.  Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
136.    Halarme(2) = Format(ComboBox4.SelectedIndex, "00") & ":" & Format(ComboBox5.SelectedIndex, "00") & ":" & Format(ComboBox6.SelectedIndex, "00")
137.    Label2.Text "Alarme " & CDate(Halarme(2))
138.    alarme(2) = True
139.  End Sub
140.
141.  Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
142.    Halarme(3) = Format(ComboBox7.SelectedIndex, "00") & ":" & Format(ComboBox8.SelectedIndex, "00") & ":" & Format(ComboBox9.SelectedIndex, "00")
143.    Label3.Text "Alarme " & CDate(Halarme(3))
144.    alarme(3) = True
145.  End Sub
146.
147.  Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
148.    Try
149.      TimeOfDay = New Date(Now.Year, Now.Month, Now.Day, ComboBox10.SelectedIndex, ComboBox11.SelectedIndex, ComboBox12.SelectedIndex)
150.    Catch ex As Exception
151.      MsgBox(Err.Number & vbLf & vbLf & Err.Description, vbExclamation)
152.    End Try
153.  End Sub
154.
155.End Class
0
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011
23 oct. 2011 à 15:13
Bonjour,

Le code de "EhJoe" m'a beaucoup aidé par contre, je ne comprends pas la manipulation qui consiste à changer l'heure.

Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Try
TimeOfDay = New Date(Now.Year, Now.Month, Now.Day, ComboBox10.SelectedIndex, ComboBox11.SelectedIndex, ComboBox12.SelectedIndex)
Catch ex As Exception
MsgBox(Err.Number & vbLf & vbLf & Err.Description, vbExclamation)
End Try
End Sub

J'ai tenté de mettre seulement timeofday = newdate (now.year, ...
mais cela ne fonctionne pas. J'ai ensuite tenté d'ajouté tout le code ci-dessus et cela génère une erreur de sécurité (Autorisation de sécurité insuffisantes pour définir l'heure système).

Je n'arrive pas à résoudre ce problème pouvez-vous m'aider?

Merci
0
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011
23 oct. 2011 à 16:10
Re à tous,

En faite, je pense avoir compris le changement d'heure dans l'horloge de "EhJoe".
Dites moi si je me trompe mais je pense que ce code est relié au système d'exploitation (windows) car l'application de changement d'heure ne fonctionne pas sur 2 pc différents.
L'erreur produite (Autorisation de sécurité insuffisantes pour définir l'heure système) nécessite, je pense, un paramètre spécifique de windows liée au changement d'horaire.

Sinon je préfèrerai faire que lorsque l'on choisit les heures, minutes, secondes dans des comboboxs et en appuyant sur un bouton validé, l'horaire se change. Ensuite pour la faire tourner, utiliser un timer qui incrémente le premier chiffre des secondes puis inclure des conditions : si le premier chiffre des secondes passe à 10 alors le deuxième passe à un puis le premier chiffre des minutes passe à 1 ... et ainsi de suite.

Help!!!

Merci
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
23 oct. 2011 à 16:52
Bonjour,

Je suis EhJoe,

En réponse, le code :
Sub Button7_Click(...
TimeOfDay = New Date(Now.Year, Now.Month, Now.Day, ComboBox10.SelectedIndex, ComboBox11.SelectedIndex, ComboBox12.SelectedIndex)

Veut dire :

Si on clique sur bouton7 l'heure et la ate sont égales (à l'année actuelle, au mois actuel, au jour actuel, à l'heure de l'index sélectionné du combobox10, à minute de l'index sélectionné du combobox11 et à la seconde de l'index sélectionné du combobox12

Tout à fait, le code est relié au système, alors ensuite je ne sais pas comment fait Windows, il peut prendre l'heure sur le Net comme un grand au démarrage, ou prende l'heure à l'horloge du PC seulement (horloge à pile il faut le rappeler).

Le blocage du réglage de l'heure vient du réglage du système, et je ne sais pas ce qu'il faut faire pour l'autoriser, peut être faudrait-il demander dans un forum Windows, c'est sans doute une affaire de propriété (encore)...

Par les API il est peut être possibile de prendre l'heure directement à l'horloge, je ne sais pas, mais ça ne changerait rien.

Le PC n'est pas une horloge mécanique autonome, seulement tributaire d'un remontage mécanique, le PC est lié à son horloge qui est cadencé par un quartz qu'on électrocute :o)

Je réponds non à ta question : On ne peut pas avoir une heure autonome, il faut bien qu'elle se cadence sur quelque chose (quartz électrifié -> horloge -> PC -> système). On peut certes faire une pseudo heure, en faisant (heure + ou - x temps), mais c'est tout.

Ce qu'il faut trouver (toi), c'est le code qui commande de pouvoir changer d'heure...

Toutefoi in fine, attention en changeant l'heure, ça peut perturber un tas de machins sur une longue période, notammenet tout ce qui fonctionneme avec l'heure (application), etc, qui ne comrpendrait guère d'exister avant l'heure par exemple, d'où un risque de déréglage ou de plantage... Imaginons un progamme qui gérerait un fichier selon sa date, il regarde s'il est plus ancien pour le changer, mais se retruve avec un fichier plus récent que la date actuelle (date future), si la situation n'est pas prévue ça peut gravement perturber le fonctionnement... Ça peut aussi être une méthode pour pièger un programme, tu changes la date dans le futur puis tu fais linstallation, puis tu cherches tous les fichiers ayant cette date...

Cordialement.

Joe.
0
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011
23 oct. 2011 à 17:15
Merci pour ta réponse, cela confirme bien ce que je pensais.
Cependant, je ne peut pas utilisé cette option pour pouvoir changer l'heure en fonction de l'heure du système puisque mon projet sera analysé par le corps enseignant et si cela ne fonctionne pas sur leurs PC alors ça serais pas bon du tout pour moi.

je voudrai faire d'une manière différente : lorsque l'on choisit les heures, minutes, secondes dans des comboboxs et en appuyant sur un bouton validé, l'horaire se change. Ensuite pour la faire tourner, utiliser un timer qui incrémente le premier chiffre des secondes puis inclure des conditions : si le 1er chiffre des secondes passe à 10 alors le 2ème passe à un (et le 1er retombe à 0) puis le premier chiffre des minutes passe à 1 ... et ainsi de suite. Je pense qu'il faudrait utiliser une boucle et des conditions.

Le problème est que je ne sait pas le faire. Donc dans un premier temps, je souhaiterai savoir comment relier un timer à un chiffre pour qu'il prenne les valeurs de 0 à 9. (Il faut savoir que je n'ai pas procédé comme toi puisque pour moi, 1 chiffre est composé de 7 picturebox représentant chacun un segment. Alors que toi, 1 chiffre est composé de 9 picturebox).

Merci beaucoup pour le temps passé à me répondre
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
23 oct. 2011 à 17:33
Bonjour,

Oui, j'ai fait plus court car je ne voulais pas y passer la nuit (on ne va pas y passer la nuit, Johnny), alors j'ai pris des images.

Toi tu as du pendre des labels, disposés dans je ne sais quoi pour le contour, et tu mets tout à gris puis à noir selon la valeur du chiffre, je présume, c'est ce qu'il faut faire... Sauf à réellment dessiner mais ce serait encore plus long, et dessiner avec vbNet c'est pas très simple.

Pour faire évoluer une bariable c'est assez simple, tu la déclares en globale :

'
' horloge (form1) : vbNet 10
Option Explicit On
Public Class Form1
Dim taVariable As Integer = 0


Tu mets ta variable dans la procédure du timer :

Sub Timer1_Tick(...
taVariable = taVariable + 1
if taVariable 10 then taVariable 0


Et quand le timer est lancé ça va avancer :

 Sub Form1_Load(ByVal ...
   Timer1.Interval = 1000
   Timer1.Enabled = True


NB : tu peux utiliser plusieurs Timer, en fait le timer se contente d'avancer du pas que tu lui donne dès que tu le lance (value = x) en millième de seconde, mais en dessous de 50/1000e c'est inexpressif, voire moins 100...
Donc tous ce que tu mets dedans s'exécute à la cadence du timer, ainsi taVariable = taVariable + 1 va avancer toutes les secondes de +1.
Deux valeurs pour le tiomer, le reste ça décore :
ENABLED = true ou false
VALUE = en 1000e
Les variables doivent être déclarées à l'extérieur du timer (global, en haut).
Tu peux arrêter ton timer depuis sa propre procdure ou en dehors.

Cordialement.

Joe.





Cordialement.

Joe.
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
24 oct. 2011 à 21:23
Salut

Tu peux télécharger ton projet à
https://rapidshare.com/files/1289478101/DigitalAlarmClock.zip
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
25 oct. 2011 à 09:04
Suite,

Je me demande concernant la fonction de remise à l'heure, c'est étonnant, car une horloge ne fonctionne pas selon l'horloge dans l'absolu, mais selon l'ordinateur, or pour remettre à l'heure l'horloge, il faut remettre à l'heure l'ordinateur, donc en avoir les droit (plus en connaître le code), on peut dire que c'est "relativement" impossible dans moult cas pratiques...

Il serait intéressant de voir le libellé du problème, ou de demander des précisions à ceux qui ont posé la question, ou encore de voir comment les autres comprennent en pratique une telle question de remise à l'heure...

Je vois bien une solution, mais une solution pour le sport, pas une solution rationnelle, ce serait d'avoir ta propre heure, en somme quand tu lances ton programme et qu'il lance le timer, on crée des variales globales
personnels de l'heure :
dim monHH as byte = heurePC
dim monMN as byte = minutePC
dim monSS as byte = secondePC (voir syntaxe)

Puis dans la procédure :

sub Timer1(...1 fois par seconde
' Tu fais
monSS = monSS + 1
if monSS 60 then monSS 0
monMN = monMN + 1
if monMN 60 then monSS 0
monHH = monHH + 1
if monHH 24 then monHH 0
-----------

Et tu ne travailles qu'avec tes trois variables d'heure personnelle

Et si on remet à l'heure la pendule, dans ta procédure tu modifie ton heure personnelle, ainsi tu te retrouves à pouvoir modifier l'heure sans toucher celle du PC, et tu ne fonctionne qu'avec ton heure, si j'ai le temps je vais te faire le programme, car c'est très facile (pour moi), mais un peu long...

Cordialement.

Joe.
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
25 oct. 2011 à 12:45
Suite et sans doute fin,

J'ai refait le code avec 6 fois 7 segments et une horloge dont on peut changer l'heure.

Pour la perfectionner il resterait à mettre un bouton qui indique si on affiche ou pas le premier 0 de l'heure, et aussi pour lalarme à gérer sur 48h00 et à prévoir donc si on met l'alarme pour aujourd'hui ou pour demain, mais on ne t'en demande sans doute pas tant :



Voici le code :

'
' horloge (form1) : vbNet 10
Option Explicit On
Public Class Form1
  Dim HH As Byte ' temps personnel
  Dim MN As Byte
  Dim SS As Byte
  Dim HHold As Byte ' temps personnel ancien
  Dim MNold As Byte
  Dim t As Integer
  Dim ri
  Dim alarme(3) As Boolean
  Dim Halarme(3) As Long
  Dim alternat As Boolean
  Dim la As New Collection() ' débute ? 1 (monObj)
  Dim depuis As Byte
  Dim afficheTout As Boolean


  Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim i As Integer
    Me.Left = 10
    Me.Top = 10
    TextBox1.Text = ""
    TextBox1.Visible = False
    afficheTout = True
    la.Add(Me.Label5) ' (i) indice objets début = 1
    la.Add(Me.Label6)
    la.Add(Me.Label7)
    la.Add(Me.Label8)
    la.Add(Me.Label9)
    la.Add(Me.Label10)
    la.Add(Me.Label11)
    '
    la.Add(Me.Label18)
    la.Add(Me.Label17)
    la.Add(Me.Label16)
    la.Add(Me.Label15)
    la.Add(Me.Label14)
    la.Add(Me.Label12)
    la.Add(Me.Label13)
    '
    la.Add(Me.Label25)
    la.Add(Me.Label24)
    la.Add(Me.Label23)
    la.Add(Me.Label22)
    la.Add(Me.Label21)
    la.Add(Me.Label19)
    la.Add(Me.Label20)
    '
    la.Add(Me.Label32)
    la.Add(Me.Label31)
    la.Add(Me.Label30)
    la.Add(Me.Label29)
    la.Add(Me.Label28)
    la.Add(Me.Label26)
    la.Add(Me.Label27)
    '
    la.Add(Me.Label39)
    la.Add(Me.Label38)
    la.Add(Me.Label37)
    la.Add(Me.Label36)
    la.Add(Me.Label35)
    la.Add(Me.Label33)
    la.Add(Me.Label34)
    '
    la.Add(Me.Label46)
    la.Add(Me.Label45)
    la.Add(Me.Label44)
    la.Add(Me.Label43)
    la.Add(Me.Label42)
    la.Add(Me.Label40)
    la.Add(Me.Label41)
    '
    For i = 0 To 59
      If i < 24 Then
        ComboBox1.Items.Add(Format(i, "00"))
        ComboBox4.Items.Add(Format(i, "00"))
        ComboBox7.Items.Add(Format(i, "00"))
        ComboBox10.Items.Add(Format(i, "00"))
      End If
      ComboBox2.Items.Add(Format(i, "00"))
      ComboBox3.Items.Add(Format(i, "00"))
      ComboBox5.Items.Add(Format(i, "00"))
      ComboBox6.Items.Add(Format(i, "00"))
      ComboBox8.Items.Add(Format(i, "00"))
      ComboBox9.Items.Add(Format(i, "00"))
      ComboBox11.Items.Add(Format(i, "00"))
      ComboBox12.Items.Add(Format(i, "00"))
    Next i
    ComboBox1.SelectedIndex = 0
    ComboBox2.SelectedIndex = 0
    ComboBox3.SelectedIndex = 0
    ComboBox4.SelectedIndex = 0
    ComboBox5.SelectedIndex = 0
    ComboBox6.SelectedIndex = 0
    ComboBox7.SelectedIndex = 0
    ComboBox8.SelectedIndex = 0
    ComboBox9.SelectedIndex = 0
    ComboBox10.SelectedIndex = 0
    ComboBox11.SelectedIndex = 0
    ComboBox12.SelectedIndex = 0
    For i = 1 To 42 ' rab
      la(i).BackColor = Color.FromArgb(233, 233, 233)
    Next i
    Timer1.Interval = 1000
    HH Now.Hour ' heure perso heure PC
    MN = Now.Minute
    SS = Now.Second
    HHold = HH
    MNold = MN
    Timer1.Enabled = True
  End Sub


  Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim lheure As Long
    SS = SS + 1
    If SS = 60 Then
      SS = 0
      MN = MN + 1
      If MN = 60 Then
        MN = 0
        HH = HH + 1
        If HH 24 Then HH 0
      End If
    End If
    Call affichePendule()
    lheure = SS + (MN * 60) + (HH * 3600)
    '
    alternat = Not alternat
    If alarme(1) = True Then
      If lheure >= Halarme(1) Then
        If alternat True Then Label1.BackColor Color.FromArgb(192, 192, 192)
        If alternat False Then Label1.BackColor Color.FromArgb(255, 0, 0)
      End If
    End If
    If alarme(2) = True Then
      If lheure >= Halarme(2) Then
        If alternat True Then Label2.BackColor Color.FromArgb(192, 192, 192)
        If alternat False Then Label2.BackColor Color.FromArgb(255, 0, 0)
      End If
    End If
    If alarme(3) = True Then
      If lheure >= Halarme(3) Then
        If alternat True Then Label3.BackColor Color.FromArgb(192, 192, 192)
        If alternat False Then Label3.BackColor Color.FromArgb(255, 0, 0)
      End If
    End If
  End Sub


  Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    HH = ComboBox10.SelectedIndex ' change d'heure
    MN = ComboBox11.SelectedIndex
    SS = ComboBox12.SelectedIndex
    Label1.BackColor = Color.FromArgb(192, 192, 192) ' si alrame ne reste pas sur rouge
    Label2.BackColor = Color.FromArgb(192, 192, 192)
    Label3.BackColor = Color.FromArgb(192, 192, 192)
    afficheTout = True
  End Sub


  Sub affichePendule()
    If HH HHold And afficheTout False Then GoTo deux
    HHold = HH
    depuis = 1
    Call ecrit()
deux:
    If MN MNold And afficheTout False Then GoTo trois
    MNold = MN
    depuis = 15
    Call ecrit()
trois:
    depuis = 29
    Call ecrit()
    If afficheTout True Then afficheTout Not afficheTout
    '
    TextBox1.Visible = False ' doublons d'alarme
    TextBox1.Text = ""
    If alarme(1) True And alarme(2) True Then
      If Halarme(1) = Halarme(2) Then
        TextBox1.Text "Heure alarme 1 heure alarme 2"
      End If
    End If
    If alarme(1) True And alarme(3) True Then
      If Halarme(1) = Halarme(3) Then
        TextBox1.Text "Heure alarme 1 heure alarme 3"
      End If
    End If
    If alarme(2) True And alarme(3) True Then
      If Halarme(2) = Halarme(3) Then
        TextBox1.Text "Heure alarme 2 heure alarme 3"
      End If
    End If
    If alarme(1) True And alarme(2) True And alarme(3) = True Then
      If Halarme(1) Halarme(2) And alarme(2) alarme(3) Then
        TextBox1.Text "Heure alarme 1 heure alarme 2 = heure alarme 3"
      End If
    End If
    If TextBox1.Text <> "" Then TextBox1.Visible = True
  End Sub


  Sub ecrit()
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim deci As Byte
    Dim unit As Byte
    For i = depuis To depuis + 13 ' rab
      la(i).BackColor = Color.FromArgb(233, 233, 233) ' rab
    Next i
    Select Case depuis ' dizaines - unités
      Case 1 ' heures
        deci = CByte(Mid(Format(HH, "00"), 1, 1))
        unit = CByte(Mid(Format(HH, "00"), 2, 1))
      Case 15 ' minutes
        deci = CByte(Mid(Format(MN, "00"), 1, 1))
        unit = CByte(Mid(Format(MN, "00"), 2, 1))
      Case 29 ' secondes
        deci = CByte(Mid(Format(SS, "00"), 1, 1))
        unit = CByte(Mid(Format(SS, "00"), 2, 1))
    End Select
    k = deci
bis:
    j = j + 1
    Select Case k
      Case 0
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 1).BackColor = Color.FromArgb(233, 233, 233) ' gris
      Case 1
        la(depuis + 3).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 4).BackColor = Color.FromArgb(0, 0, 0)
      Case 2
        For i = depuis To depuis + 3
          la(i).BackColor = Color.FromArgb(0, 0, 0)
        Next i
        la(depuis + 5).BackColor = Color.FromArgb(0, 0, 0)
      Case 3
        For i = depuis To depuis + 4
          la(i).BackColor = Color.FromArgb(0, 0, 0)
        Next i
      Case 4
        la(depuis + 1).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 3).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 4).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 6).BackColor = Color.FromArgb(0, 0, 0)
      Case 5
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 3).BackColor = Color.FromArgb(233, 233, 233) ' gris
        la(depuis + 5).BackColor = Color.FromArgb(233, 233, 233) ' gris
      Case 6
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 3).BackColor = Color.FromArgb(233, 233, 233) ' gris
      Case 7
        la(depuis).BackColor = Color.FromArgb(0, 0, 0) ' noir
        la(depuis + 3).BackColor = Color.FromArgb(0, 0, 0) ' noir
        la(depuis + 4).BackColor = Color.FromArgb(0, 0, 0) ' noir
      Case 8
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
      Case 9
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 5).BackColor = Color.FromArgb(233, 233, 233) ' gris
    End Select
    If j > 1 Then Return
    k = unit
    depuis = depuis + 7
    GoTo bis
  End Sub


  Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim h, m, s As Byte ' déclenche alarme 1
    h = ComboBox1.SelectedIndex
    m = ComboBox2.SelectedIndex
    s = ComboBox3.SelectedIndex
    Halarme(1) = s + (m * 60) + (h * 3600)
    Label1.Text "Alarme " & h & ":" & Format(m, "00") & ":" & Format(s, "00")
    alarme(1) = True
  End Sub


  Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    alarme(1) = False ' stoppe alarme 1
    Label1.BackColor = Color.FromArgb(192, 192, 192)
    Label1.Text = "Alarme à l'arrêt"
  End Sub


  Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    Dim h, m, s As Byte ' déclenche alarme 2
    h = ComboBox4.SelectedIndex
    m = ComboBox5.SelectedIndex
    s = ComboBox6.SelectedIndex
    Halarme(2) = s + (m * 60) + (h * 3600)
    Label2.Text "Alarme " & h & ":" & Format(m, "00") & ":" & Format(s, "00")
    alarme(2) = True
  End Sub


  Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    alarme(2) = False ' stoppe alarme 2
    Label2.BackColor = Color.FromArgb(192, 192, 192)
    Label2.Text = "Alarme à l'arrêt"
  End Sub


  Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    Dim h, m, s As Byte ' déclenche alarme 3
    h = ComboBox7.SelectedIndex
    m = ComboBox8.SelectedIndex
    s = ComboBox9.SelectedIndex
    Halarme(3) = s + (m * 60) + (h * 3600)
    Label3.Text "Alarme " & h & ":" & Format(m, "00") & ":" & Format(s, "00")
    alarme(3) = True
  End Sub


  Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    alarme(3) = False ' stoppe alarme 3
    Label3.BackColor = Color.FromArgb(192, 192, 192)
    Label3.Text = "Alarme à l'arrêt"
  End Sub


End Class


Et voici d'où tu peux télécharger le fichier zipé de la source :


Télécharger

http://mesromans.free.fr/horlogeperso.zip

Cordialement.

Joe.
0
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011
30 oct. 2011 à 20:15
Merci à tous pour vos réponses.

Cordialement
0
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011
30 oct. 2011 à 20:18
Cela m'a permis de mener à bien mon projet (enfin je crois )

Je vous tiendrai au courant du résultat si cela vous intéresse et je reviendrai volontiers sur ce forum en cas de nouveaux projets et d'autres problèmes.
Accueil très simpa et efficace.

(+1 à EhJoe) et merci à tous.

Cordialement
0
camay76 Messages postés 13 Date d'inscription mercredi 5 octobre 2011 Statut Membre Dernière intervention 31 octobre 2011
31 oct. 2011 à 10:26
Bonjour,

Je viens de m’apercevoir qu'il me manque un élément dans mon projet. Je dois pouvoir enregistrer mes 3 alarmes dans un fichier et faire que si elles sont enregistrées, elles se chargeront au démarrage du programme.

Je pense faire un bouton pour chaque alarme et le coder de sorte que cela affiche la boite permettant de choisir le lieu ou l'on veut l'enregistrer, le nom de l'enregistrement ...

Si quelqu'un pouvais m'aider ce serai super!

Merci
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
31 oct. 2011 à 13:16
Bonjour,

Voici avec un fichier, code à mettre en totalité en remplacement du précédent :

'
' horloge (form1) : vbNet 10
Option Explicit On
Public Class Form1
  Dim HH As Byte ' temps personnel
  Dim MN As Byte
  Dim SS As Byte
  Dim HHold As Byte ' temps personnel ancien
  Dim MNold As Byte
  Dim t As Integer
  Dim ri
  Dim alarme(3) As Boolean
  Dim Halarme(3) As Long
  Dim alternat As Boolean
  Dim la As New Collection() ' débute ? 1 (monObj)
  Dim depuis As Byte
  Dim afficheTout As Boolean
  Dim vientDe As Byte
  Dim ligne(3) As String


  Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim i As Integer
    Dim j As Byte = 1
    Me.Left = 10
    Me.Top = 10
    TextBox1.Text = ""
    TextBox1.Visible = False
    afficheTout = True
    la.Add(Me.Label5) ' (i) indice objets début = 1
    la.Add(Me.Label6)
    la.Add(Me.Label7)
    la.Add(Me.Label8)
    la.Add(Me.Label9)
    la.Add(Me.Label10)
    la.Add(Me.Label11)
    '
    la.Add(Me.Label18)
    la.Add(Me.Label17)
    la.Add(Me.Label16)
    la.Add(Me.Label15)
    la.Add(Me.Label14)
    la.Add(Me.Label12)
    la.Add(Me.Label13)
    '
    la.Add(Me.Label25)
    la.Add(Me.Label24)
    la.Add(Me.Label23)
    la.Add(Me.Label22)
    la.Add(Me.Label21)
    la.Add(Me.Label19)
    la.Add(Me.Label20)
    '
    la.Add(Me.Label32)
    la.Add(Me.Label31)
    la.Add(Me.Label30)
    la.Add(Me.Label29)
    la.Add(Me.Label28)
    la.Add(Me.Label26)
    la.Add(Me.Label27)
    '
    la.Add(Me.Label39)
    la.Add(Me.Label38)
    la.Add(Me.Label37)
    la.Add(Me.Label36)
    la.Add(Me.Label35)
    la.Add(Me.Label33)
    la.Add(Me.Label34)
    '
    la.Add(Me.Label46)
    la.Add(Me.Label45)
    la.Add(Me.Label44)
    la.Add(Me.Label43)
    la.Add(Me.Label42)
    la.Add(Me.Label40)
    la.Add(Me.Label41)
    '
    For i = 0 To 59
      If i < 24 Then
        ComboBox1.Items.Add(Format(i, "00"))
        ComboBox4.Items.Add(Format(i, "00"))
        ComboBox7.Items.Add(Format(i, "00"))
        ComboBox10.Items.Add(Format(i, "00"))
      End If
      ComboBox2.Items.Add(Format(i, "00"))
      ComboBox3.Items.Add(Format(i, "00"))
      ComboBox5.Items.Add(Format(i, "00"))
      ComboBox6.Items.Add(Format(i, "00"))
      ComboBox8.Items.Add(Format(i, "00"))
      ComboBox9.Items.Add(Format(i, "00"))
      ComboBox11.Items.Add(Format(i, "00"))
      ComboBox12.Items.Add(Format(i, "00"))
    Next i
    Try ' lecture et si erreur = création
      Dim p As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\horloge.txt"))
      p.Close()
    Catch ex As Exception
      Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\horloge.txt"))
      p1.WriteLine("999999") ' pas d'alarme
      p1.WriteLine("999999")
      p1.WriteLine("999999")
      p1.Close()
    End Try
    Dim p2 As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\horloge.txt"))
    ligne(1) = p2.ReadLine()
    ligne(2) = p2.ReadLine()
    ligne(3) = p2.ReadLine()
    p2.Close()
    i = Val(Mid(ligne(j), 1, 2))
    If i 99 Then ComboBox1.SelectedIndex 0
    If i <> 99 Then ComboBox1.SelectedIndex = i
    i = Val(Mid(ligne(j), 3, 2))
    If i 99 Then ComboBox2.SelectedIndex 0
    If i <> 99 Then ComboBox2.SelectedIndex = i
    i = Val(Mid(ligne(j), 5, 2))
    If i 99 Then ComboBox3.SelectedIndex 0
    If i <> 99 Then ComboBox3.SelectedIndex = i
    j = j + 1
    i = Val(Mid(ligne(j), 1, 2))
    If i 99 Then ComboBox4.SelectedIndex 0
    If i <> 99 Then ComboBox4.SelectedIndex = i
    i = Val(Mid(ligne(j), 3, 2))
    If i 99 Then ComboBox5.SelectedIndex 0
    If i <> 99 Then ComboBox5.SelectedIndex = i
    i = Val(Mid(ligne(j), 5, 2))
    If i 99 Then ComboBox6.SelectedIndex 0
    If i <> 99 Then ComboBox6.SelectedIndex = i
    j = j + 1
    i = Val(Mid(ligne(j), 1, 2))
    If i 99 Then ComboBox7.SelectedIndex 0
    If i <> 99 Then ComboBox7.SelectedIndex = i
    i = Val(Mid(ligne(j), 3, 2))
    If i 99 Then ComboBox8.SelectedIndex 0
    If i <> 99 Then ComboBox8.SelectedIndex = i
    i = Val(Mid(ligne(j), 5, 2))
    If i 99 Then ComboBox9.SelectedIndex 0
    If i <> 99 Then ComboBox9.SelectedIndex = i
    ComboBox10.SelectedIndex = 0
    ComboBox11.SelectedIndex = 0
    ComboBox12.SelectedIndex = 0
    For j = 1 To 3
      Select Case j ' <> 0 = déclenche alarme
        Case 1 : If Val(ligne(j)) <> 999999 Then Call Button1_Click(sender, e)
        Case 2 : If Val(ligne(j)) <> 999999 Then Call Button4_Click(sender, e)
        Case 3 : If Val(ligne(j)) <> 999999 Then Call Button6_Click(sender, e)
      End Select
    Next j
    For i = 1 To 42 ' rab
      la(i).BackColor = Color.FromArgb(233, 233, 233)
    Next i
    Timer1.Interval = 1000
    HH Now.Hour ' heure perso heure PC
    MN = Now.Minute
    SS = Now.Second
    HHold = HH
    MNold = MN
    Timer1.Enabled = True
  End Sub


  Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim lheure As Long
    SS = SS + 1
    If SS = 60 Then
      SS = 0
      MN = MN + 1
      If MN = 60 Then
        MN = 0
        HH = HH + 1
        If HH 24 Then HH 0
      End If
    End If
    Call affichePendule()
    lheure = SS + (MN * 60) + (HH * 3600)
    '
    alternat = Not alternat
    If alarme(1) = True Then
      If lheure >= Halarme(1) Then
        If alternat True Then Label1.BackColor Color.FromArgb(192, 192, 192)
        If alternat False Then Label1.BackColor Color.FromArgb(255, 0, 0)
      End If
    End If
    If alarme(2) = True Then
      If lheure >= Halarme(2) Then
        If alternat True Then Label2.BackColor Color.FromArgb(192, 192, 192)
        If alternat False Then Label2.BackColor Color.FromArgb(255, 0, 0)
      End If
    End If
    If alarme(3) = True Then
      If lheure >= Halarme(3) Then
        If alternat True Then Label3.BackColor Color.FromArgb(192, 192, 192)
        If alternat False Then Label3.BackColor Color.FromArgb(255, 0, 0)
      End If
    End If
  End Sub


  Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    HH = ComboBox10.SelectedIndex ' change d'heure
    MN = ComboBox11.SelectedIndex
    SS = ComboBox12.SelectedIndex
    Label1.BackColor = Color.FromArgb(192, 192, 192) ' si alrame ne reste pas sur rouge
    Label2.BackColor = Color.FromArgb(192, 192, 192)
    Label3.BackColor = Color.FromArgb(192, 192, 192)
    afficheTout = True
  End Sub


  Sub affichePendule()
    If HH HHold And afficheTout False Then GoTo deux
    HHold = HH
    depuis = 1
    Call ecrit()
deux:
    If MN MNold And afficheTout False Then GoTo trois
    MNold = MN
    depuis = 15
    Call ecrit()
trois:
    depuis = 29
    Call ecrit()
    If afficheTout True Then afficheTout Not afficheTout
    '
    TextBox1.Visible = False ' doublons d'alarme
    TextBox1.Text = ""
    If alarme(1) True And alarme(2) True Then
      If Halarme(1) = Halarme(2) Then
        TextBox1.Text "Heure alarme 1 heure alarme 2"
      End If
    End If
    If alarme(1) True And alarme(3) True Then
      If Halarme(1) = Halarme(3) Then
        TextBox1.Text "Heure alarme 1 heure alarme 3"
      End If
    End If
    If alarme(2) True And alarme(3) True Then
      If Halarme(2) = Halarme(3) Then
        TextBox1.Text "Heure alarme 2 heure alarme 3"
      End If
    End If
    If alarme(1) True And alarme(2) True And alarme(3) = True Then
      If Halarme(1) Halarme(2) And alarme(2) alarme(3) Then
        TextBox1.Text "Heure alarme 1 heure alarme 2 = heure alarme 3"
      End If
    End If
    If TextBox1.Text <> "" Then TextBox1.Visible = True
  End Sub


  Sub ecrit()
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim deci As Byte
    Dim unit As Byte
    For i = depuis To depuis + 13 ' rab
      la(i).BackColor = Color.FromArgb(233, 233, 233) ' rab
    Next i
    Select Case depuis ' dizaines - unités
      Case 1 ' heures
        deci = CByte(Mid(Format(HH, "00"), 1, 1))
        unit = CByte(Mid(Format(HH, "00"), 2, 1))
      Case 15 ' minutes
        deci = CByte(Mid(Format(MN, "00"), 1, 1))
        unit = CByte(Mid(Format(MN, "00"), 2, 1))
      Case 29 ' secondes
        deci = CByte(Mid(Format(SS, "00"), 1, 1))
        unit = CByte(Mid(Format(SS, "00"), 2, 1))
    End Select
    k = deci
bis:
    j = j + 1
    Select Case k
      Case 0
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 1).BackColor = Color.FromArgb(233, 233, 233) ' gris
      Case 1
        la(depuis + 3).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 4).BackColor = Color.FromArgb(0, 0, 0)
      Case 2
        For i = depuis To depuis + 3
          la(i).BackColor = Color.FromArgb(0, 0, 0)
        Next i
        la(depuis + 5).BackColor = Color.FromArgb(0, 0, 0)
      Case 3
        For i = depuis To depuis + 4
          la(i).BackColor = Color.FromArgb(0, 0, 0)
        Next i
      Case 4
        la(depuis + 1).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 3).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 4).BackColor = Color.FromArgb(0, 0, 0)
        la(depuis + 6).BackColor = Color.FromArgb(0, 0, 0)
      Case 5
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 3).BackColor = Color.FromArgb(233, 233, 233) ' gris
        la(depuis + 5).BackColor = Color.FromArgb(233, 233, 233) ' gris
      Case 6
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 3).BackColor = Color.FromArgb(233, 233, 233) ' gris
      Case 7
        la(depuis).BackColor = Color.FromArgb(0, 0, 0) ' noir
        la(depuis + 3).BackColor = Color.FromArgb(0, 0, 0) ' noir
        la(depuis + 4).BackColor = Color.FromArgb(0, 0, 0) ' noir
      Case 8
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
      Case 9
        For i = depuis To depuis + 6
          la(i).BackColor = Color.FromArgb(0, 0, 0) ' noir
        Next i
        la(depuis + 5).BackColor = Color.FromArgb(233, 233, 233) ' gris
    End Select
    If j > 1 Then Return
    k = unit
    depuis = depuis + 7
    GoTo bis
  End Sub


  Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim h, m, s As Byte ' déclenche alarme 1
    h = ComboBox1.SelectedIndex
    m = ComboBox2.SelectedIndex
    s = ComboBox3.SelectedIndex
    Halarme(1) = s + (m * 60) + (h * 3600)
    Label1.Text "Alarme " & h & ":" & Format(m, "00") & ":" & Format(s, "00")
    alarme(1) = True
    vientDe = 11
    Call ecritFichier()
  End Sub


  Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    alarme(1) = False ' stoppe alarme 1
    Label1.BackColor = Color.FromArgb(192, 192, 192)
    Label1.Text = "Alarme à l'arrêt"
    vientDe = 10
    Call ecritFichier()
  End Sub


  Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    Dim h, m, s As Byte ' déclenche alarme 2
    h = ComboBox4.SelectedIndex
    m = ComboBox5.SelectedIndex
    s = ComboBox6.SelectedIndex
    Halarme(2) = s + (m * 60) + (h * 3600)
    Label2.Text "Alarme " & h & ":" & Format(m, "00") & ":" & Format(s, "00")
    alarme(2) = True
    vientDe = 21
    Call ecritFichier()
  End Sub


  Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    alarme(2) = False ' stoppe alarme 2
    Label2.BackColor = Color.FromArgb(192, 192, 192)
    Label2.Text = "Alarme à l'arrêt"
    vientDe = 20
    Call ecritFichier()
  End Sub


  Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    Dim h, m, s As Byte ' déclenche alarme 3
    h = ComboBox7.SelectedIndex
    m = ComboBox8.SelectedIndex
    s = ComboBox9.SelectedIndex
    Halarme(3) = s + (m * 60) + (h * 3600)
    Label3.Text "Alarme " & h & ":" & Format(m, "00") & ":" & Format(s, "00")
    alarme(3) = True
    vientDe = 31
    Call ecritFichier()
  End Sub


  Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    alarme(3) = False ' stoppe alarme 3
    Label3.BackColor = Color.FromArgb(192, 192, 192)
    Label3.Text = "Alarme à l'arrêt"
    vientDe = 30
    Call ecritFichier()
  End Sub


  Sub ecritFichier()
    Dim p2 As New System.IO.StreamReader(CStr(My.Application.Info.DirectoryPath & "\horloge.txt"))
    ligne(1) = p2.ReadLine()
    ligne(2) = p2.ReadLine()
    ligne(3) = p2.ReadLine()
    p2.Close()
    Select Case vientDe
      Case 10 : ligne(1) = "999999"
      Case 11
        ligne(1) = Format(ComboBox1.SelectedIndex, "00") & Format(ComboBox2.SelectedIndex, "00")
        ligne(1) = ligne(1) & Format(ComboBox3.SelectedIndex, "00")
      Case 20 : ligne(2) = "999999"
      Case 21
        ligne(2) = Format(ComboBox4.SelectedIndex, "00") & Format(ComboBox5.SelectedIndex, "00")
        ligne(2) = ligne(2) & Format(ComboBox6.SelectedIndex, "00")
      Case 30 : ligne(3) = "999999"
      Case 31
        ligne(3) = Format(ComboBox7.SelectedIndex, "00") & Format(ComboBox8.SelectedIndex, "00")
        ligne(3) = ligne(3) & Format(ComboBox9.SelectedIndex, "00")
    End Select
    Dim p1 As New System.IO.StreamWriter(CStr(My.Application.Info.DirectoryPath & "\horloge.txt"))
    p1.WriteLine(ligne(1)) ' pas d'alarme
    p1.WriteLine(ligne(2))
    p1.WriteLine(ligne(3))
    p1.Close()
  End Sub

End Class


Cordialement, Joe.
0
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
31 oct. 2011 à 14:16
Salut EhJoe

GoTo bis

les goto doivent etre éviter en vb et autre langage
0
ehjoe Messages postés 728 Date d'inscription samedi 4 avril 2009 Statut Membre Dernière intervention 30 mars 2014 4
31 oct. 2011 à 16:51
Bonjour ShayW,

De la légende tout ça, le goto est une directive VB, elle est faite pour être utilisée, en fait pour remonter c'est souvent le plus pratique.

Ça vient à l'origine du Basic QB et caetera, dans lequel certaines personne peut habituées faisaient une forêt inextricable de goto qui plantaient le PC par des bourcle sans sortie.

Comme tu peux le voir mon code permet une sortie totalement normale. J'aurais pu utiliser une boucle, mais quand le goto est plus rapide à écrire que la boucle, ben je prends le plus rapide...

Bien utilisé je revendique l'emloi du goto comme tout autre code

Cordialement, Joe.
0
Rejoignez-nous