Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

String to Time Calculations

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
JackW9653
Asked:
JackW9653
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
TertioptusCommented:
So what exactly is your problem.
0
 
JackW9653Author Commented:
I need a method to determine End Time by adding the Hour+Minute+Duration.
0
 
Wayne Taylor (webtubbs)Commented:
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Wayne Taylor (webtubbs)Commented:
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
 
JackW9653Author Commented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
JackW9653Author Commented:
Thanks IM, worked perfectly.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Uhm...I just added Integer.Parse() and Double.Parse() to the code submitted by webtubbs....   =\
0
 
JackW9653Author Commented:
Can I adjust the points then to give webtubbs some? Not sure how to go about doing that.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now