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 and the type seems to be double, which I find strange
because it seem to only output (long) integers anyway. The same thing goes
for the date field. 2007-01-26 (today) is output as 20070126 from the date
field.

Since I want time and date to be copied to spreadsheet cells using its date
and time formats, I need to convert those "integers" to something that shows
up as date and time in the spreadsheet. I did that this, probably
unnecessary way:

The cells are pre-formatted as date and time respectively, so the macro does
nothing to the cell formats. 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.

Besst regards

Johnny

Reply via email to