Il codice seguente se scritto in FMain.class di una nuova applicazione grafica funziona, ma non mi convince e pertanto rinnovo la domanda in oggetto :-\
Private $hTime As Date
Private $sTime As String
Private $hTimer As Timer
Public Sub Form_Open()
Dim hButton As Button
With Me
.W = 240
.H = 152
.Margin = True
.Arrangement = Arrange.Fill
End With
With hButton = New Button(Me) As "Button1"
.Text = "Avvia il confronto Time"
End With
With $hTimer = New Timer As "Timer1"
.Delay = 1000
.Ignore = True
End With
End
Public Sub Timer1_Timer()
Dim hNow As Date = Time(Now)
Dim sNow As String = Format(hNow, "hh:nn:ss")
Print hNow;; $hTime
''If hNow = $hTime Then '' perché questo non funziona? :-/
If sNow = $sTime Then '' e invece questo funziona ma...
Print "UGUALE"
$hTimer.Stop
Endif
End
Public Sub Button1_Click()
$hTimer.Start
$hTime = Time(Hour(Now), Minute(Now) + 1, 0)
$sTime = Format($hTime, "hh:nn:ss")
End
Probabilmente il modo più corretto è questo:
Private $hTimer As Timer
Private $iHour As Integer
Private $iMinute As Integer
Public Sub Form_Open()
Dim hButton As Button
With Me
.W = 240
.H = 152
.Margin = True
.Arrangement = Arrange.Fill
End With
With hButton = New Button(Me) As "Button1"
.Text = "Avvia il confronto Time"
End With
With $hTimer = New Timer As "Timer1"
.Delay = 1000
.Ignore = True
End With
End
Public Sub Timer1_Timer()
Dim iHour As Integer = Hour(Now)
Dim iMinute As Integer = Minute(Now)
Print iHour; ":"; iMinute;; $iHour; ":"; $iMinute
If iHour = $iHour And If iMinute = $iMinute Then
Print "UGUALE"
$hTimer.Stop
Endif
End
Public Sub Button1_Click()
$hTimer.Start
$iHour = Hour(Now)
$iMinute = Minute(Now) + 1
End
:ciao:
Penso che tu non consideri i millisecondi
Se formatti il tuo tempo con la stringa "hh:nn:ss.uuu" vedrai che hNow e $hTime sono diversi
Lo avevo notato usando cstr(), comunque mi hai illuminato :) per il confronto occorre usare DateDiff :
Private $hTime As Date
Private $hTimer As Timer
Public Sub Form_Open()
Dim hButton As Button
With Me
.W = 240
.H = 152
.Margin = True
.Arrangement = Arrange.Fill
End With
With hButton = New Button(Me) As "Button1"
.Text = "Avvia il confronto Time"
End With
With $hTimer = New Timer As "Timer1"
.Delay = 1000
.Ignore = True
End With
End
Public Sub Timer1_Timer()
Dim hNow As Date = Time(Now)
Print DateDiff($hTime, hNow, gb.Second)
If DateDiff($hTime, hNow, gb.Second) = 0 Then
Print "UGUALE"
$hTimer.Stop
Endif
End
Public Sub Button1_Click()
$hTimer.Start
$hTime = Time(Hour(Now), Minute(Now) + 1, 0)
End
:ciao: