Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a time as a variable

Status
Not open for further replies.

hockeyman9474

IS-IT--Management
Oct 11, 2007
17
US
I am attempting to pass time as a variable. The textbox on the form that the time will be passed into is set to short time. I use input box to get the time from the user like this starttime=inputbox("Enter Time"). Regardless of what is entered the time plugged into the forms' textbox looks like 100 and not 1:00. I figured it has something to do with how the variable is dimmed or do I need something in front of inputbox like time(inputbox=("Enter Time"))?

thanks
Adam
 
An input box entry is going to be text. If the user enters a formatted time (like "12:21PM") you can use the timevalue function to return a time (which is an integer, internally).

_________________
Bob Rashkin
 
so instead of inputbox() i use timevalue()?

I also hardcoded for the length of time to equal the difference in hours. Should this still work with the possability of a time not on the hour?

If txtStart = 12 Then
txtLength = txtEnd & "Hours"
ElseIf txtStart < txtEnd Then
txtLength = txtEnd - txtStart & "Hours"
ElseIf txtStart > txtEnd Then
If txtStart = 11 Then
txtLength = txtEnd + 1 & "Hours"
ElseIf txtStart = 10 Then
txtLength = txtEnd + 2 & "Hours"
ElseIf txtStart = 9 Then
txtLength = txtEnd + 3 & "Hours"
ElseIf txtStart = 8 Then
txtLength = txtEnd + 4 & "Hours"
ElseIf txtStart = 7 Then
txtLength = txtEnd + 5 & "Hours"
ElseIf txtStart = 6 Then
txtLength = txtEnd + 6 & "Hours"
ElseIf txtStart = 5 Then
txtLength = txtEnd + 7 & "Hours"
ElseIf txtStart = 4 Then
txtLength = txtEnd + 8 & "Hours"
ElseIf txtStart = 3 Then
txtLength = txtEnd + 9 & "Hours"
ElseIf txtStart = 2 Then
txtLength = txtEnd + 10 & "Hours"
ElseIf txtStart = 1 Then
txtLength = txtEnd + 11 & "Hours"
End If
End If
 




maybe...
Code:
    If txtStart = 12 Then
        txtLength = txtEnd & "Hours"
    ElseIf txtStart < txtEnd Then
        txtLength = txtEnd - txtStart & "Hours"
    ElseIf txtStart > txtEnd Then[b]
        txtLength = txtEnd + 12 - txtStart & "Hours"[/b]
        End If
    End If
???

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Actually I found this code on microsofts website but I am still having trouble having the user input a time. I think I nees to use TimeValue() and not inputbox(), correct?


Function ElapsedTime(endTime As Date, startTime As Date)
Dim strOutput As String
Dim Interval As Date

' Calculate the time interval.
Interval = endTime - startTime


' Format and print the time interval in hours, minutes and seconds.
strOutput = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
& " Hours:Minutes:Seconds"
Debug.Print strOutput

End Function
 
You need to use InputBox if you want to prompt the user to input information. However the returned value from InputBox is a string so you need to use TimeValue(string) to return a time:
TimeValue(InputBox(your prompt)) will return a time, but only if the user inputs a "properly formatted" time string.

_________________
Bob Rashkin
 

And why not use a combo holding the hours and onother for minutes? Then

TimeValue(combo1 & ":" & combo2)

should always have a valid time. You could also limit the combo1 to hold only working hours if you like!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top