Option Explicit
Private Sub ControlloData(Giorno As TextBox)
If IsDate(Giorno) = False Then
MsgBox "Errore, tipo non corrispondente" & vbCrLf & "Inserire la data in formato: gg\mm\aaaa", vbCritical
Giorno.Text = Date
Giorno.SelStart = 0
Giorno.SelLength = Len(Giorno)
Giorno.SetFocus
End If
End Sub
Private Function GiornoSettimana(Giorno As Date) As String
If Weekday(Giorno) = 1 Then GiornoSettimana = "domenica"
If Weekday(Giorno) = 2 Then GiornoSettimana = "lunedì"
If Weekday(Giorno) = 3 Then GiornoSettimana = "martedì"
If Weekday(Giorno) = 4 Then GiornoSettimana = "mercoledì"
If Weekday(Giorno) = 5 Then GiornoSettimana = "giovedì"
If Weekday(Giorno) = 6 Then GiornoSettimana = "venerdì"
If Weekday(Giorno) = 7 Then GiornoSettimana = "sabato"
End Function
Private Sub Form_Load()
picOrologio.Scale (-4500, 4500)-(4500, -4500)
txtData1.Text = Date
txtData2.Text = Date
lblDifferenza.Caption = ""
End Sub
Private Sub optTempo_Click(Index As Integer)
Dim Anni As Integer
Dim Mesi As Long
Dim Giorni As Long
If IsDate(txtData1) = True And IsDate(txtData2) = True Then
Giorni = Abs(DateDiff("d", txtData1, txtData2))
Mesi = Abs(DateDiff("m", txtData1, txtData2))
Anni = Mesi / 12
lblData1.Caption = GiornoSettimana(txtData1)
lblData2.Caption = GiornoSettimana(txtData2)
If Index = 0 Then lblDifferenza.Caption = "Tra le 2 date intercorrono " & Giorni & " giorni"
If Index = 0 And Giorni = 1 Then lblDifferenza.Caption = "Tra le 2 date intercorre un giorno"
If Index = 1 Then lblDifferenza.Caption = "Tra le 2 date intercorrono " & Mesi & " mesi"
If Index = 1 And Mesi = 1 Then lblDifferenza.Caption = "Tra le 2 date intercorre un mese"
If Index = 2 Then lblDifferenza.Caption = "Tra le 2 date intercorrono " & Anni & " anni"
If Index = 2 And Anni = 1 Then lblDifferenza.Caption = "Tra le 2 data intercorre un anno"
End If
If IsDate(txtData1) = True Then ControlloData txtData2
ControlloData txtData1
End Sub
Private Sub tmOrologio_Timer()
Dim Sec, Min, Ore As Integer
Const Pi As Double = 3.14159
Sec = Second(Time)
Min = Minute(Time)
Ore = Hour(Time)
lnSec.X2 = Sin(Sec * 6 * Pi / 180) * 4000
lnSec.Y2 = Cos(Sec * 6 * Pi / 180) * 4000
lnMin.X2 = Sin((Min + Sec / 60) * 6 * Pi / 180) * 3500
lnMin.Y2 = Cos((Min + Sec / 60) * 6 * Pi / 180) * 3500
lnOre.X2 = Sin((Ore + Min / 60) * 30 * Pi / 180) * 3000
lnOre.Y2 = Cos((Ore + Min / 60) * 30 * Pi / 180) * 3000
lblOra.Caption = Time
lblOraAmPm.Caption = Format(Time, "h:nn:ss AM/PM")
End Sub
Private Sub txtData1_Change()
optTempo(0).Value = False
optTempo(1).Value = False
optTempo(2).Value = False
lblDifferenza.Caption = ""
End Sub
Private Sub txtData2_Change()
txtData1_Change
End Sub