Hello all,

I found this piece of code below which returnes the date of a file. When I try to run it, I says a sub-program wasn't defined (see my marker). This sub-program is in the file 'QB.BI'.

Here's the code:
VB Code:
  1. '===========================================================================
  2.  
  3. ' Subject: GET/SET FILE DATE/TIME            Date: Unknown Date (00:00)  
  4. ' Author:  Matt Hart                         Code: QB, PDS                
  5. ' Keys:    GET,SET,FILE,DATE,TIME          Packet: DOS.ABC
  6. '===========================================================================
  7. ' FILEDATE.BAS  by Matt Hart
  8. '
  9. ' Gets or sets a file date/time
  10. '
  11. ' GetFileDateTime returns the Date in MM-DD-YYYY format
  12. '                     and the Time in HH:MM:SS
  13. ' SetFileDateTime expects the Date and Time in the same formats
  14.  
  15.     '$INCLUDE: 'QB.BI'    ' Use your path to QB or QBX.BI
  16.     DEFINT A-Z
  17.     DECLARE SUB GetFileDateTime (F$, Dat$, Tim$, Ecode%)
  18.     DECLARE SUB SetFileDateTime (F$, Dat$, Tim$, Ecode%)
  19.  
  20. ' ------------------------- Sample code
  21.     F$ = LTRIM$(RTRIM$(COMMAND$))
  22.     CALL GetFileDateTime(F$, Dat$, Tim$, Ecode)
  23.     IF NOT Ecode THEN
  24.            PRINT F$; " date is "; Dat$
  25.            PRINT F$; " time is "; Tim$
  26.     ELSE
  27.            PRINT "1 Error = "; Ecode
  28.            END
  29.     END IF
  30.     NewTim$ = "01:01:02"
  31.     NewDat$ = "02-02-1980"
  32.     CALL SetFileDateTime(F$, NewDat$, NewTim$, Ecode)
  33.     IF Ecode THEN
  34.            PRINT "2 Error = "; Ecode
  35.            END
  36.     END IF
  37.     CALL GetFileDateTime(F$, Dat$, Tim$, Ecode)
  38.     IF Ecode THEN
  39.            PRINT "3 Error = "; Ecode
  40.            END
  41.     END IF
  42.     PRINT F$; " new date is "; Dat$
  43.     PRINT F$; " new time is "; Tim$
  44.     CALL SetFileDateTime(F$, Dat$, Tim$, Ecode)
  45.     IF Ecode THEN
  46.            PRINT "4 Error = "; Ecode
  47.            END
  48.     END IF
  49.     END
  50. ' ------------------------------------
  51.  
  52. SUB GetFileDateTime (F$, Dat$, Tim$, Ecode)
  53.     Ecode = 0
  54.     DIM InRegs AS RegTypeX
  55.     DIM OutRegs AS RegTypeX
  56.     InRegs.ax = &H3D00                          ' Open file function
  57.     DIM FileName AS STRING * 128                ' Use fixed length
  58.     FileName = F$ + CHR$(0)                     ' Must be ASCIIZ string
  59.     InRegs.ds = VARSEG(FileName)                ' Fixed length makes these
  60.     InRegs.dx = VARPTR(FileName)                ' come out right
  61.     CALL INTERRUPTX(&H21, InRegs, OutRegs)      ' Open the file
  62.   ''''''***** IT STOPS HERE in the line CALL INTERRUPTX
  63.     IF NOT OutRegs.flags THEN                   ' No error
  64.            Handle = OutRegs.ax                     ' Save DOS file handle
  65.            InRegs.ax = &H5700                      ' Get date/time function
  66.            InRegs.bx = Handle
  67.            CALL INTERRUPTX(&H21, InRegs, OutRegs)
  68.            HMS& = OutRegs.cx                       ' Use long integer for
  69.            IF HMS& < 0& THEN HMS& = 65536 + HMS&   ' positive numbers
  70.            Hours = HMS& \ 2048&                    ' Hours is first 5 bits
  71.            Minutes = (HMS& AND 2047&) \ 31&        ' Minutes is next 6 bits
  72.            Seconds = HMS& AND 31&                  ' Seconds is last 5 bits
  73.            H$ = LTRIM$(STR$(Hours))
  74.            M$ = LTRIM$(STR$(Minutes)): IF LEN(M$) = 1 THEN M$ = "0" + M$
  75.            S$ = LTRIM$(STR$(Seconds)): IF LEN(S$) = 1 THEN S$ = "0" + S$
  76.            Tim$ = H$ + ":" + M$ + ":" + S$
  77.            YMD& = OutRegs.dx                       ' Long int here too
  78.            IF YMD& < 0 THEN YMD& = 65536 + YMD&    ' Convert to + if needed
  79.            Year = 1980& + YMD& \ 512&              ' Year is first 7 bits
  80.            Month = (YMD& AND 511&) \ 31&           ' Month is next 4 bits
  81.            Day = YMD& AND 31&                      ' Day is last 5 bits
  82.            Y$ = LTRIM$(STR$(Year))
  83.            M$ = LTRIM$(STR$(Month))
  84.            D$ = LTRIM$(STR$(Day)): IF LEN(D$) = 1 THEN D$ = "0" + D$
  85.            Dat$ = M$ + "-" + D$ + "-" + Y$
  86.            InRegs.ax = &H3E00                      ' Close file function
  87.            InRegs.bx = Handle
  88.            CALL INTERRUPTX(&H21, InRegs, OutRegs)  ' Close it
  89.     ELSE
  90.  
  91.            Ecode = OutRegs.flags       ' Otherwise return error flags
  92.     END IF
  93. END SUB
  94.  
  95. SUB SetFileDateTime (F$, Dat$, Tim$, Ecode)
  96.     Ecode = 0
  97.     DIM InRegs AS RegTypeX
  98.     DIM OutRegs AS RegTypeX
  99.     InRegs.ax = &H3D00
  100.     DIM FileName AS STRING * 128
  101.     FileName = F$ + CHR$(0)
  102.     InRegs.ds = VARSEG(FileName)
  103.     InRegs.dx = VARPTR(FileName)
  104.     CALL INTERRUPTX(&H21, InRegs, OutRegs)
  105.     IF NOT OutRegs.flags THEN
  106.            Handle = OutRegs.ax
  107.            InRegs.ax = &H5701
  108.            InRegs.bx = Handle
  109.            Hours& = VAL(LEFT$(Tim$, 2)) * 2048&
  110.            Minutes& = VAL(MID$(Tim$, 4, 2)) * 32&
  111.            Seconds& = VAL(RIGHT$(Tim$, 2)) \ 2
  112.            HMS& = Hours& + Minutes& + Seconds&
  113.            IF HMS& > 65536 THEN
  114.                   InRegs.cx = 65536 - HMS&
  115.            ELSE
  116.                   InRegs.cx = HMS&
  117.            END IF
  118.            Year& = (VAL(RIGHT$(Dat$, 4)) - 1980&) * 512&
  119.            Month& = VAL(LEFT$(Dat$, 2)) * 32&
  120.            Day& = VAL(MID$(Dat$, 4, 2))
  121.            YMD& = Year& + Month& + Day&
  122.            IF YMD& > 65536 THEN
  123.                   InRegs.dx = 65536 - YMD&
  124.            ELSE
  125.                   InRegs.dx = YMD&
  126.            END IF
  127.            CALL INTERRUPTX(&H21, InRegs, OutRegs)
  128.            InRegs.ax = &H3E00
  129.            InRegs.bx = Handle
  130.            CALL INTERRUPTX(&H21, InRegs, OutRegs)
  131.     ELSE
  132.            Ecode = OutRegs.flags
  133.     END IF
  134. END SUB

Matt