Wilder1626
asked on
VB6 - Convert HH:MM into Decimal
Hi,
I need your help to convert a time in a textbox1 to be converted into Decimal value.
Normally, in Excel, if i have 00:10 (10 minutes) the decimal value would be 0.17.
The excel formula would be:
But now, i would like to do the same thing but in VB6 and the time would be entered in the TextBox1.
I would like to get the Decimal result in Textbox2.
How can i do that?
Thanks for your help
I need your help to convert a time in a textbox1 to be converted into Decimal value.
Normally, in Excel, if i have 00:10 (10 minutes) the decimal value would be 0.17.
The excel formula would be:
=INT(A1)*24+ROUND(MINUTE(A1)/60,2)
But now, i would like to do the same thing but in VB6 and the time would be entered in the TextBox1.
I would like to get the Decimal result in Textbox2.
How can i do that?
Thanks for your help
Will the TextBox1 value always be hours and minutes?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much. This is exactly what i was looking for.
I don't know how the value gets into Textbox1 but if it's user entered then you might want to add lines 3 to 6.
If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.
Marty - Microsoft MVP 2009 to 2016
Experts Exchange MVE 2015
Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
Dim intMin As Integer
Dim strParts() As String
If Len(Text1.Text) - 1 <> Len(Replace(Text1.Text, ":", "")) Then
MsgBox "A string in the form hh:mm or h:mm is expected, please try again"
Exit Sub
End If
strParts = Split(Text1.Text, ":")
intMin = strParts(1) + 60 * strParts(0)
Text2.Text = Round(intMin / 60, 2)
In any case you're welcome and I'm glad I was able to help.If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.
Marty - Microsoft MVP 2009 to 2016
Experts Exchange MVE 2015
Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
ASKER
Thanks Martin, I will definitely add lines 3 to 6. Good idea as the vale is added manually.
Since a user can put anything in a textbox you probably should use a MaskedEdit control instead as in the attached.
MaskedEdit.zip
MaskedEdit.zip
ASKER
wow, i've to go with your MaskedEdit control. That a very good idea. Thanks again