Help in Select Case

bitong

New member
Joined
Sep 5, 2007
Messages
4
Programming Experience
Beginner
Please help me on how to finish my program..the problem is i have to make a program wherein i will type the start time and the end time, get the length of time..using the 24 -hour clock. using only Select case, no if/else

here's my unfinished code:

VB.NET:
Console.Write("Enter start time: ")
st = console.ReadLine()
Console.write("Enter end time: ")
et = console.ReadLine()
diff = (et - st)
Console.Write("Length of the call is: {0}", diff)
Select Case et
Case 1801 To 2400
com1 = 0.6 
Case 100 To 759
com2 = 0.6
Case 800 To 1800
com3 = 0.9
End Select
It's easy to know the length of the call but the main problem is that the per minute call varies on certain length of hour...for 6:01 pm to 8:00 am - $0.6
and 8:01 a.m. to 6:00 pm is $0.9, i really have a hard time figuring out how to know if that certain time lands on the sepecific range..Please help
 
Last edited by a moderator:
I think you're looking for something like this, inputting time values for example "08:00"
VB.NET:
    Sub Main()
        Console.Write("Enter start time: ")
        Dim st As Date = Date.Parse(Console.ReadLine())
        Console.Write("Enter end time: ")
        Dim et As Date = Date.Parse(Console.ReadLine())
        Console.WriteLine("total length of call in minutes: " & et.Subtract(st).TotalMinutes.ToString)
        Dim intervals(2) As Date
        intervals(0) = Date.Parse("00:00")
        intervals(1) = Date.Parse("08:00")
        intervals(2) = Date.Parse("18:00")
        Dim cost As Double
        Do While st < et
            st = st.AddMinutes(1)
            Select Case st
                Case intervals(0) To intervals(1)
                    cost += 0.2
                Case intervals(1) To intervals(2)
                    cost += 0.9
                Case Else
                    cost += 0.6
            End Select
        Loop
        Console.WriteLine("total cost of call: " & cost.ToString("c", New Globalization.CultureInfo("en-us")))
        Console.ReadKey()
    End Sub
 
Hello John, Thank you so much for the reply...Is there any other form, the simplest one,that I can understand?...I'm still a newbie in vb.net and some of your codes I've not come to know yet...
 
Back
Top