Fran�ois Van Emelen wrote:



Hi all, Could someone explain me this?

P1
100 a$="SMSQE"
110 b$=a$(4 to 3)
120 print b$,len(b$)

Line 120 prints an empty string with length 0.

P2
100 a$="SMSQE"
110 b$=a$(4 to 2)
120 print b$,len(b$)

Line 120 returns the error 'unacceptable array index list'

Question: Why doesn't P1 return the same error as P2?

It actually seems to be a logical result when you consider that a slice of A$(m TO n) returns n - m + 1 characters (eg m = 4):


   n = m     {a$(4 TO 4)} -> 4 - 4 + 1 =  1 character returned
   n = m - 1 {a$(4 TO 3)} -> 3 - 4 + 1 =  0 characters returned, which *IS*
                                              a legal string length: an
                                              empty string ("")
   n = m - 2 {a$(4 TO 2)} -> 2 - 4 + 1 = -1 characters returned, which *IS*
                                              *NOT* a legal string length.

Whether this is intended or not is the question; I believe it dates back to the original QL - I had a friend who was writing a simple text editor in basic, but I remember that he had to add an extra space to the end of every line to avoid such crashing errors.



  • ... François Van Emelen
    • ... Marcel Kilgus
    • ... Robert Newson
      • ... François Van Emelen
        • ... "Phoebus R. Dokos (Φοίβος Ρ. Ντόκος)"
          • ... Dilwyn Jones
            • ... "Phoebus R. Dokos (Φοίβος Ρ. Ντόκος)"
            • ... Dave P
              • ... "Phoebus R. Dokos (Φοίβος Ρ. Ντόκος)"
              • ... "Phoebus R. Dokos (Φοίβος Ρ. Ντόκος)"
            • ... Bill Waugh

Reply via email to