Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# String to Time Calculations

Posted on 2007-08-06
Medium Priority
192 Views
Hello Experts,
I have 3 combo boxes the are Hours (01 -24), Minutes (15, 30, 45) and Duration (15 - 120 in 15 increments). I need to combine Hours + Minutes to determine a Starting Time, obviously in Military time (ie 1330) and the add the duration to get Ending Time. This is a VB.Net CF app.

Thanks,

JackW9653
0
Question by:JackW9653
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3
• 2
• +1

LVL 5

Expert Comment

ID: 19639525
So what exactly is your problem.
0

Author Comment

ID: 19639547
I need a method to determine End Time by adding the Hour+Minute+Duration.
0

LVL 47

Accepted Solution

Wayne Taylor (webtubbs) earned 1000 total points
ID: 19639571
Hello JackW9653,

Use something like this....

Dim StartTime As Date = New Date(1, 1, 1, cbHours.Text, cbMinutes.Text, 0)
Dim EndTime As Date = StartTime.AddMinutes(cbDuration.Text)
MsgBox(EndTime.ToString("HHmm"))

Regards,

Wayne
0

LVL 47

Expert Comment

ID: 19639603
Or, even shorter....

Dim StartTime As Date = New Date(1, 1, 1, cbHours.Text, cbMinutes.Text, 0).AddMinutes(cbDuration.Text)
MsgBox(EndTime.ToString("HHmm"))

Wayne
0

Author Comment

ID: 19639628
Hi Wayne and thanks for the quick reply. Gets the "Implicit Conversion from 'String' to 'Integer' Error for the cbHours.text and cbMinutes.txt and "Implicit Conversion from 'String' To 'Double' for cbDuratation.txt
0

LVL 86

Assisted Solution

Mike Tomlinson earned 1000 total points
ID: 19639789
If you have Option Strict On then you will need to convert the values from your ComobBoxes into numeric values.

This can be done using CInt(), Integer.Parse(), etc...

Dim StartTime As Date = New Date(1, 1, 1, Integer.Parse(cbHours.Text), Integer.Parse(cbMinutes.Text), 0).AddMinutes(Double.Parse(cbDuration.Text))

0

Author Comment

ID: 19639921
Thanks IM, worked perfectly.
0

LVL 86

Expert Comment

ID: 19639942
Uhm...I just added Integer.Parse() and Double.Parse() to the code submitted by webtubbs....   =\
0

Author Comment

ID: 19645972
Can I adjust the points then to give webtubbs some? Not sure how to go about doing that.
0

LVL 86

Expert Comment

ID: 19646562
You would have to post a request here for the question to be reopened so you can Split Points:
http://www.experts-exchange.com/Community_Support/General/

Then see this link for how to Split Points:
http://www.experts-exchange.com/help.jsp#hi69
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)â€¦
Wouldnâ€™t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldnâ€™t it be good if you could write code like this? (CODE) In .NET 3.5, this is possibleâ€¦
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vulnâ€¦
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increasedâ€¦
###### Suggested Courses
Course of the Month4 days, 12 hours left to enroll