Microsoft Small Basic

Program Listing: WDZ371
' SmallBasic Version 1.1
' Program: TimeDiff
' Changelog:
' Author: Pappa Lapub
' Website: https://social.msdn.microsoft.com/Forums/en-US/3b975ffc-cbfd-407c-ab95-74912e57c65d/challenge-of-the-month-april-2015
' ImportURL: http://smallbasic.com/program/?
' Extension:
' Comment: Small Challenges, Write a TextWindow program to read in 2 times of the day
' (24 hour clock) and calculate the number of minutes between the 2 times,
' eg 10:25 and 14:12 is 227 minutes.
' Variables:
' ToDo:
' ================================================================================
TextWindow.WriteLine("Enter times [hh:mm] from 0:00 to 23:59, 'q' to quit.")
TextWindow.WriteLine(" (""+ means 0:00)")
TextWindow.WriteLine("")

While time <> "q"
cnt = Math.Remainder(cnt, 2) + 1
TextWindow.Write(cnt + ". time [hh:mm]: ")
time = Text.ConvertToLowerCase(TextWindow.Read())

If time <> "q" Then
pos = Text.GetIndexOf(time, ":")
hh[cnt] = Text.GetSubText(time, 1,pos-1)
mm[cnt] = Text.GetSubTextToEnd(time, pos+1)
CheckFormat()
If cnt = 2 Then
ShowResult()
pos = ""
hh = ""
mm = ""
EndIf
EndIf
EndWhile
TextWindow.WriteLine("")


' ////////// SUBs \\\\\\\\\\
Sub CheckFormat
If hh[cnt] < 0 Or hh[cnt] > 23 Or mm[cnt] < 0 Or mm[cnt] > 59 Then
TextWindow.WriteLine(" * Wrong time format! (hh: 0-23, mm: 0-59)")
cnt = cnt-1
EndIf
EndSub

Sub ShowResult
dmins = (hh[2] - hh[1]) * 60 - mm[1] + mm[2]
If dmins < 0 Then
dmins = Text.Append(dmins, " same day (or "+ (1440+dmins) +" next day)")
EndIf
TextWindow.WriteLine("TimeDiff [min] = " + dmins)
TextWindow.WriteLine("")
EndSub