X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 05 Oct 2009 06:40 PM by  anon
IDL Starting
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
05 Oct 2009 06:40 PM
    Dear all I am a new, (yes very new) student, attempting to learn how to Programming in IDL (I tried these on IDL Version 6.3). When I coded a simple program to get information from Keyboard, the code is exactly below: PRO GetInfor    ; do nothing    ;myArray END FUNCTION GetInput, myArray, nElements myArray=MAKE_ARRAY(nElements,/INTEGER ,value=0) FOR i=0, nElements DO BEGIN  READ, myArray[i] ENDFOR T = myArray RETURN, T END When I called getInput from the other Pro called Display.pro PRO Display  T=getInput(myArray,5)  FOR i=0,5 DO BEGIN   PRINT, T[i]  ENDFOR END The result is:   So I saw the for loop in the first function did not work at all. Please tell me what happened? And could you help me to solve it? IDL> display 0 0 0 0 0Attempt to subscript MYARRAY with I is out of range. Execution halted at: GETINPUT 9 C:\IDLExercises\getinfor.pro DISPLAY 3 C:\IDLExercises\display.pro $MAIN$

    Deleted User



    New Member


    Posts:
    New Member


    --
    06 Oct 2009 05:36 AM
    Hi, The problem is due to your "For" loop that must be executed 5 times (i=0,1,2,3,4) not 6 (i=0,1,2,3,4,5) as you have coded it. Best regards. Patrice.   PRO Display  T=getInput(myArray,5)  FOR i=0, 4 DO BEGIN   PRINT, T[i]  ENDFOR END
    You are not authorized to post a reply.