Message de Johnny Andersson  date 2007-01-26 09:30 :
Forget about what I said about the type of Time and Date from those fields
in the dialog I was talking about. I checked again and they are Long, not
Double. Sorry for missleading...   =)

But I still wonder about the rest of what I wrote...

Johnny

2007/1/26, Johnny Andersson <[EMAIL PROTECTED]>:

Hi!

Once again in some kind of troubles when trying to communicate with a
spreadsheet using a macro.
I created a dialog with a time field in it. The problem is that the time
format is just a number, for example if it's 18:45, the time field will
output 18450000 (...). The same thing
goes
for the date field. 2007-01-26 (today) is output as 20070126 from the date
field.

(...) I created these two functions for
converting Control field time and date to the numberformat that can be
formatted to readable date and time:


'***************************************************************************
Function DateCtlFieldToDate(Dt As Long) As Date
    Dim Y As Long, M As Long, D As Long

    Y=Int(Dt/10000)
    M=Int(Dt/100)-Y*100
    D=Dt-Y*10000-M*100
    DateCtlFieldToDate=DateSerial(Y,M,D)
End Function


'***************************************************************************
Function TimeCtlFieldToTime(Tm As Long) As Date
    Dim H As Long, M As Long, S As Long

    H=Int(Tm/1000000)
    M=Int(Tm/10000)-H*100
    S=Int(Tm/100)-H*10000-M*100
    TimeCtlFieldToTime=TimeSerial(H,M,S)
End Function

'***************************************************************************


Now to my question:
Do I really need these two functions? Isn't there an easier way? I
couldn't find a built in function for doing this, so that's why I tried to
create my own maybe not so fast ones.

AFAIK there is no existing conversion function for time.
For date, you get from the TimeField control a value which is an ISO date format. Here Basic provides a function:

Dim Tm As Long, Tm2 As Date
Tm2 = CDateFromISO(Tm)

   Bernard

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to