Hi all,
I have a series of textboxes in a userform that need to be added up... the answer goes into a final textbox, which can be altered if necessary. The basic idea is "end time - start time - lunch time + travel time = total."
I was using this code to achieve it, which worked fine when all the textboxes contained straight-up numbers (eg 9.5):
The entry needs to be very intuitive however, since I'm making this for someone else who isn't very computer-savvy. the Start time and End time need to be written like "9:30 a" or "10:00 p" while the lunch and travel times will be decimals (.5, 1.25)...
I can't figure out how to get those different kinds of values to add and subtract within this basic code framework... mostly because I don't actually know what the "double" is doing... I tried taking it away and just adding the values (with the decimals divided by 24) but that didn't work, and I don't know what else to convert to/format as to make this work.
This might be easy... but I couldn't find a solution online that combined the issue of the textboxes/vba with the issue of adding disparate formats... and although I'm a decent coder, I've just never been able to understand dim'ing things as double, single, long.
As a side note, I know that "on error resume next" isn't a great tactic... but I'll deal with that later!
Thanks so much for any help,
Katherine
I have a series of textboxes in a userform that need to be added up... the answer goes into a final textbox, which can be altered if necessary. The basic idea is "end time - start time - lunch time + travel time = total."
I was using this code to achieve it, which worked fine when all the textboxes contained straight-up numbers (eg 9.5):
Code:
Dim dblSum As Double
On Error Resume Next
dblSum = CDbl(Start1.Value)
dblSum = (dblSum) * (-1) + CDbl(End1.Value)
dblSum = dblSum - CDbl(Lunch1.Value)
dblSum = dblSum + CDbl(Travel1.Value)
Total1 = dblSum
The entry needs to be very intuitive however, since I'm making this for someone else who isn't very computer-savvy. the Start time and End time need to be written like "9:30 a" or "10:00 p" while the lunch and travel times will be decimals (.5, 1.25)...
I can't figure out how to get those different kinds of values to add and subtract within this basic code framework... mostly because I don't actually know what the "double" is doing... I tried taking it away and just adding the values (with the decimals divided by 24) but that didn't work, and I don't know what else to convert to/format as to make this work.
This might be easy... but I couldn't find a solution online that combined the issue of the textboxes/vba with the issue of adding disparate formats... and although I'm a decent coder, I've just never been able to understand dim'ing things as double, single, long.
As a side note, I know that "on error resume next" isn't a great tactic... but I'll deal with that later!
Thanks so much for any help,
Katherine