one from a datetime picker n the other is a text field.. Am using this query.. dim arrtime as datetime arrtime = (Ccur(txttime.value)+( Ccur(txtdot.text)).. It shows type mismatch error...

Recommended Answers

Your problem lies in your declaring a datetime, but you are using CCur (currency) to gte a value. to calculate 2 dates, do the following by using CDate and DateDiff functions -

' Calculate user logged time in and out.
' =========================================================================
' ssno ===> User …
Jump to Post

All 4 Replies

Your problem lies in your declaring a datetime, but you are using CCur (currency) to gte a value. to calculate 2 dates, do the following by using CDate and DateDiff functions -

' Calculate user logged time in and out.
' =========================================================================
' ssno ===> User social security number or User assigned ID
' TimeIn ===> actual Date and Time in by user e.g. 08-11-2005 10:21:45 AM
' TimeOut ===> Actual Date and Time out by user E.G. 08-13-2005 04:10:14 PM
' =========================================================================

''In your module - ....
Public Function TOTALTIME(ssno As String, TimeIn, TimeOut)
    Dim xTime_in, xTime_out
    Dim Over_All_In_Minute As Double
    If Not IsEmpty(ssno) Or Not IsNull(ssno) Then
        Calculate_TimeIn = CDate(TimeIn)
        Calculate_TimeOut = CDate(TimeOut)
        Number_Of_Hour_Worked = DateDiff("h", Calculate_TimeIn, _
        ' Calculate minute
        Minutecalculatedx = DateDiff("n", TimeIn, TimeOut)
        Over_All_In_Minute = Round((Minutecalculatedx Mod 60), 2)
        ' Calculate total hour worked
        ' ============================================
        TotalHourWorked = Val(Str(Number_Of_Hour_Worked)) & "." & Val(Str(Over_All_In_Minute))
        ' Calculate overtime hour worked
        ' ============================================
        If Val(TotalHourWorked) > 8 Then
           Overtime_Hour_Worked = (TotalHourWorked - 8)
        End If
        OvertimeHourvalue = Overtime_Hour_Worked
        ' Calculate regular hour worked
        ' ============================================
        'RegularHour = (TotalHourWorked - Overtime_Hour_Worked)
        TOTALTIME = TotalHourWorked
    End If
End Function

''''''' In your form - .....
txtResult.Text = TOTALTIME("Rizvi404", txtTime, txtDot)

Am new to vb just tell how to add two time fields suppose 7 am is the time of departure n 00:30 is the time taken how to add this n store in a variable..

Somebody please help tat code i tried but aint workin.. Please please post a solution for addin 2 time fields..


Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download file.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.