Turning numbers into a readable time. [modified]
-
Hi guys, I'm new to programming and the first language I'm trying to learn is VB .NET. It's going pretty well for me, but I have a question and I was wondering if anyone here might be able to help me. I have a text box set up to get information from the user, once that is computed an anwser anywhere from 0 minutes to 180000 minutes. I was wondering if there is a tutorial, or a few lines of code that would be able to change the raw data of 180,000 minutes to days/hours/minutes in three different text boxes. For example, if the user entered a number which got them 129,564 minutes that would display as 89 days 23 hours and 24 minutes. Thanks a lot, aqzman EDIT: I thought this code might work, but it never. Haha. If Time > 1440 Then Time = (Time / 60) Time = (Time / 24) txtDisplay.Text = Time End If If Time < 1440 Then Time = (Time / 60) txtDisplayHour.Text = Time End If If Time < 60 Then Time = (Time) txtDisplayMin.Text = Time End If -- modified at 19:50 Monday 2nd October, 2006
-
Hi guys, I'm new to programming and the first language I'm trying to learn is VB .NET. It's going pretty well for me, but I have a question and I was wondering if anyone here might be able to help me. I have a text box set up to get information from the user, once that is computed an anwser anywhere from 0 minutes to 180000 minutes. I was wondering if there is a tutorial, or a few lines of code that would be able to change the raw data of 180,000 minutes to days/hours/minutes in three different text boxes. For example, if the user entered a number which got them 129,564 minutes that would display as 89 days 23 hours and 24 minutes. Thanks a lot, aqzman EDIT: I thought this code might work, but it never. Haha. If Time > 1440 Then Time = (Time / 60) Time = (Time / 24) txtDisplay.Text = Time End If If Time < 1440 Then Time = (Time / 60) txtDisplayHour.Text = Time End If If Time < 60 Then Time = (Time) txtDisplayMin.Text = Time End If -- modified at 19:50 Monday 2nd October, 2006
You're on the right track. You need to use the Mod operator ( it's % in C#, I suspect it's Mod in the ever literal VB ). This will return to you the remainder of your division. So, if you have 63 minutes in Time, Time Mod 60 would give you 3, the number of seconds.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog