Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error on READ
#1
Apart from my calendar dilemma, I'm also writing a program that converts roman numerals into arabic numbers. Here's what I have so far:

Code:
DECLARE SUB roman (r$(), a())
DECLARE SUB calendar ()
DECLARE SUB calendar2 ()
DECLARE SUB menu ()
'1/27/05
'Calendar and Numeral Program
'

CLS

DIM r$(13)

DIM a(13)

READ r$

READ a

DO

        menu

        a$ = INPUT$(1)

        SELECT CASE a$

                CASE "1"

                        calendar

                CASE "2"

                        roman r$(), a()

                CASE "3"
                        
              
                CASE "4"

                        CLS
                        LOCATE 20, 40
                        PRINT "Goodbye"


        END SELECT


LOOP UNTIL a$ = "4"

DATA M, CM, D, CD, C, XC, L, XL, X, IX, V, IV, I
DATA 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1

SUB calendar

CLS

INPUT "Enter a date"; d
INPUT "Enter a month"; m
INPUT "Enter a year"; y

IF m = 1 THEN

        m = 13
        y = y - 1

END IF

IF m = 2 THEN

        m = 14
        y = y - 1

END IF

n = d + 2 * m + INT(3 * (m + 1) / 5) + y + INT(y / 4) - INT(y / 100) + INT(y / 400) + 2

x = n MOD 7

IF x = 0 THEN

        PRINT "Saturday"

END IF

IF x = 1 THEN

        PRINT "Sunday"

END IF

IF x = 2 THEN

        PRINT "Monday"

END IF

IF x = 3 THEN

        PRINT "Tuesday"

END IF

IF x = 4 THEN

        PRINT "Wednesday"

END IF

IF x = 5 THEN

        PRINT "Thursday"

END IF

IF x = 6 THEN

        PRINT "Friday"

END IF

calendar2

a$ = INPUT$(1)

CLS

END SUB

SUB calendar2

CLS

LOCATE 4, 7: PRINT "Sunday"
LOCATE 4, 17: PRINT "Monday"
LOCATE 4, 27: PRINT "Tuesday"
LOCATE 4, 36: PRINT "Wednesday"
LOCATE 4, 47: PRINT "Thursday"
LOCATE 4, 57: PRINT "Friday"
LOCATE 4, 67: PRINT "Saturday"

FOR x = 5 TO 30                           'creates left border
        LOCATE x, 5
        PRINT CHR$(219)
NEXT x

FOR x = 5 TO 30                           'creates right border
        LOCATE x, 75
        PRINT CHR$(219)
NEXT x

FOR x = 5 TO 75                           'creates top border
        LOCATE 5, x
        PRINT CHR$(219)
NEXT x

FOR x = 5 TO 75                           'creates bottom border
        LOCATE 30, x
        PRINT CHR$(219)
NEXT x


                                    'creates five rows
r = 5
DO
        FOR x = 5 TO 75
                LOCATE r, x
                PRINT CHR$(219)
        NEXT x
        r = r + 5
LOOP UNTIL r = 30


c = 5                                     'creates seven columns
DO
        FOR x = 5 TO 30
                LOCATE x, c
                PRINT CHR$(219)
        NEXT x
        c = c + 10
LOOP UNTIL c = 75

END SUB

SUB menu
      
        LOCATE 10, 28: PRINT "Welcome to my Program!"
  
        LOCATE 12, 25
        PRINT "================================"

        LOCATE 14, 25
        PRINT "1) Calendar"

        LOCATE 16, 25
        PRINT "2) Roman to Arabic"

        LOCATE 18, 25
        PRINT "3) Arabic to Roman"

        LOCATE 20, 25
        PRINT "4) Quit"
      
        LOCATE 22, 25
        PRINT "================================"

END SUB

SUB roman (r$(), a())

CLS

DO

        INPUT "Enter a roman numeral"; w$

        p = 1001

        a$ = UCASE$(w$)

        c = LEN(w$)

        FOR y = 1 TO c

                w$ = MID$(a$, y, 1)

                FOR x = 1 TO 13

                        IF r$(x) = w$ THEN

                                k = x

                        EXIT FOR

                        END IF

                NEXT x

                h = a(k)

                IF h <= p THEN

                        s = s + h

                        p = h

                ELSEIF h > p THEN

                        s = s - h

                        s = -s

                        p = h

                END IF

        NEXT y

        PRINT s

        INPUT "Would you like to go again? (y/n)"; u$

        p = 1001

LOOP WHILE u$ = "y"

CLS

END SUB

Whenever I run my program, I always get a syntax error that's related to my read statements. Does anybody know how to fix this?
Reply
#2
The way you have it now:

Code:
READ r$
READ a

Will read "M" into r$ and attempt to read "CM" into a, which is where you're getting the syntax error, because a is not a string. Looks like you want to read the whole line of data into the r$ and a arrays, in which case you need to use something like this:

Code:
FOR i = 1 TO 13
  READ r$(i)
NEXT
FOR i = 1 TO 13
  READ a(i)
NEXT
Reply
#3
Oh, that fixed it! Thank you very much! Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)