Shop OBEX P1 Docs P2 Docs Learn Events
lookup question — Parallax Forums

lookup question

ArchiverArchiver Posts: 46,084
edited 2003-01-13 16:47 in General Discussion
I'm doing the following to convert the day (1-7) to text however, it
seems that there must be a better way. Anyone?

dow var byte(3)
day var byte '1=Sun, 2=Mon,...,7=Sat

lookup day-1,[noparse][[/noparse]"SMTWTFS"],dow(0)
lookup day-1,[noparse][[/noparse]"uouehra"],dow(1)
lookup day-1,[noparse][[/noparse]"nneduit"],dow(2)

' dow now contains "Sun, Mon, etc"

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-01-13 16:47
    That depends on what you're doing with the string data. If you don't need to
    hold it, that is, you just want to convert a number to a string and send it
    somewhere (i.e., a serial stream), you can do this:

    day VAR Nib
    idx VAR Byte
    eePtr VAR Byte
    char VAR Byte

    DayStr DATA "SUNMONTUEWEDTHUFRISAT"

    Main:
    FOR day = 1 TO 7
    GOSUB Print_Day
    DEBUG CR
    NEXT
    END

    Print_Day:
    eePtr = (day - 1 ) * 3
    FOR idx = eePtr TO (eePtr + 2)
    READ idx, char
    DEBUG char
    NEXT
    RETURN


    DEBUG can be replaced with SEROUT (plus appropriate parameters).


    -- Jon Williams
    -- Parallax



    In a message dated 1/13/2003 8:36:50 AM Central Standard Time,
    gtdesrosi@c... writes:

    > I'm doing the following to convert the day (1-7) to text however, it
    > seems that there must be a better way. Anyone?
    >
    > dow var byte(3)
    > day var byte '1=Sun, 2=Mon,...,7=Sat
    >
    > lookup day-1,[noparse][[/noparse]"SMTWTFS"],dow(0)
    > lookup day-1,[noparse][[/noparse]"uouehra"],dow(1)
    > lookup day-1,[noparse][[/noparse]"nneduit"],dow(2)
    >
    > ' dow now contains "Sun, Mon, etc"



    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.