'===========================================================================
' Subject: Month and Day Names                Date: 06-13-03 (  :  )       
'  Author: David Williams                     Code: Qbasic, QB, PDS, PB    
'  Origin: david.williams@ablelink.org      Packet: DATETIME.ABC
'===========================================================================
' MNTHNAME.BAS
' David Williams, 2003
' david.williams@ablelink.org

' Function MonthName$(N%) returns the name of the N%th month of
' the year. With minor changes, the same technique can be used for
' the names of days of the week, and so on.

DECLARE FUNCTION MonthName$ (N%)

DO
  INPUT "Number of month (1 - 12)"; N%
  IF N% < 1 OR N% > 12 THEN END
  Name$ = MonthName$(N%)
  PRINT "That month is "; Name$; "."
  PRINT
LOOP

 

FUNCTION MonthName$ (N%)
  'produces the name of the N%th month
  W$ = "January,February,March,April,May,June,July,"
  W$ = W$ + "August,September,October,November,December"
  Q% = 0
  FOR X% = 1 TO N%
    P% = Q% + 1
    Q% = INSTR(P%, W$, ",")
  NEXT
  IF Q% = 0 THEN Q% = LEN(W$) + 1
  MonthName$ = MID$(W$, P%, Q% - P%)
END FUNCTION

