Announcement

Collapse
No announcement yet.

illegal function call

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • illegal function call

    in another post, http://www.powerbasic.com/support/pb...ad.php?t=20285
    i asked for a more efficient way to sort the letters in a word.
    jose's reply sparked a remembrence and i modified a short sort
    routine i developed in the days of the ti/99-4a.

    got it to work okay in cc but since cc doesn't have mtimer, i
    copied it over the pb/dos and did some minor restructure so i
    could see how fast it operates. here is the dos version:
    Code:
        $lib all off
        $error all on
        color 14,1
        cls
    
        text$ = "zyxwvutsrqponmlkjihgfedcba"
        locate 1,1 : print;text$;
    
        text$ = sortword$(text$)
        locate 2,1 : print;text$;
        end
    
    function sortword$(text$)
    
        for x = 2 to len(text$)
        l = x
    
    10  do until mid$(text$,l,1) => mid$(text$,l-1,1) or l = 1
    
        s1$ = mid$(text$,l-1,1)
        mid$(text$,l-1,1) = mid$(text$,l,1)
        mid$(text$,l,1) = s1$
        l = l - 1
    
        loop
        next x
        function = text$
    
        end function
    it compiles okay but trying to run it produces an "illegal function
    call" on line 10 and i can't figure out why. the exact same thing
    compiles and runs fine under cc but not dos. i am running xp/pro.

    any ideas? thanks.


    ------------------


    [this message has been edited by mel bishop (edited october 19, 2003).]
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    Code:
    DO UNTIL MID$(text$,L,1) => MID$(text$,L-1,1) OR L = 1
    Not tested, but....

    You need to check if L=1 BEFORE you use 'L-1' in the MID$ statement, otherwise you are taking MID$(text$, 0,....)

    So try this..
    Code:
    DO UNTIL L=1 OR MID$(text$,L,1) => MID$(text$,L-1,1)
    .. to force exit before the illegal MID$ statement is even attempted.


    MCM


    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Mel,

      Here's a function and a 2 liner you can use. IIRC PB/DOS did things like this.
      DIM A(1 TO LEN(Text)) AS BYTE AS STRPTR(Text)
      ARRAY SORT A()

      Code:
      FUNCTION SortWord ( BYVAL Text AS STRING ) AS STRING
      
        DIM L AS LOCAL INTEGER
        L = LEN(Text)
      
        IF L > 1 THEN
          DIM A(L-1) AS BYTE AT STRPTR(Text)
          ARRAY SORT A()
        END IF
        
        FUNCTION = Text
      
      END FUNCTION
      ------------------
      C'ya
      Don
      [email protected]
      C'ya
      Don

      http://www.ImagesBy.me

      Comment

      Working...
      X