Solved

String to Time Calculations

Posted on 2007-08-06
10
188 Views
Last Modified: 2013-11-26
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
Comment
Question by:JackW9653
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:Tertioptus
ID: 19639525
So what exactly is your problem.
0
 

Author Comment

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

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 250 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
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

by:JackW9653
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 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 250 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

by:JackW9653
ID: 19639921
Thanks IM, worked perfectly.
0
 
LVL 85

Expert Comment

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

Author Comment

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

Expert Comment

by:Mike Tomlinson
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question