Shop OBEX P1 Docs P2 Docs Learn Events
Variable loosing it's value — Parallax Forums

Variable loosing it's value

FearTurtlesFearTurtles Posts: 89
edited 2014-10-10 07:55 in Propeller 1
In this bit of code I'm trying to print the variable "FileOne" on the screen twice. The first time it prints just fine and the second time it seems to be ignored all together.
Pub Directory |   x  ,y 
  VGAPlacement (2,0,1)
  VGAText.Str (String("Enter the Recipe number"))
  VGAPlacement (0,2,0)
  SD.Mount(0)
    'ifnot sd.partitionMounted
    'Mount(0)
  x := 1
  repeat 2
                      statusVal[x] := SD.NextFileInfo("N")                 'Retrieve file name
     Case x
        0 : x++  
        1 : FileOne := StatusVal[X]                                         'Transfering to a unique var name
               VGAtext.dec (x)                                              'print number
               VGAtext.str (String(" "))
               VGAtext.Str (FileOne)                                         'Print file name  ****Prints file name just fine here ****
               VGAtext.out ($0D)                                             'return
           x++                                                               'Advances x
        2 : FileTwo := StatusVal[X]                                          'Same as 1
               VGAtext.dec (x)
               VGAtext.str (String(" "))
               VGAtext.str (FileTwo)
               VGAtext.out ($0D)
           X++              
  SD.Unmount                                                                 Unmounts SD
  
  Repeat 
    Ekey := Keyboard.key                                                     'Waits for Key number 1-9
       Case EKey
           "1" : VGAText.Str (String(">>>>"))                                '*****This prints**Remove later**Just to show progression*****
                 VGAtext.Str (FileOne)                                       'This does not print at all.  Somehow varable is loosing its value
                 VGAText.str (String("<<<<Nothing printed ?"))               '*****This prints**Remove later**Just to show progression*****

                 'FileName := StatusVal[1]
                 'LoadFile
           "2" : FileName := StatusVal[2]
                 LoadFile

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2014-10-09 05:33
    You don't show the whole code so can only guess. In particular perhaps the VGAtext
    object you are using may interpret carriage-return as carriage-return?
  • FearTurtlesFearTurtles Posts: 89
    edited 2014-10-09 06:16
    The Variable "FileOne" is only used in the code I posted. The first time it is used it contains a file name which is printed just fine. The Carriage return only takes the cursor to the next line on the screen. I exit the first repeat loop and go to the Ekey loop where it waits for me to press a number key. When I press 1 the string ">>>>" is printed then the string"<<<<Nothing printed ?" is printed. But the FileOne is not printed in between those two strings.
  • kuronekokuroneko Posts: 3,623
    edited 2014-10-09 06:29
    The call to NextFileInfo looks like it returns a pointer to an internal buffer (which SD object are you using?). Given that the loop runs twice it may well be that the second call clears the internal buffer (i.e. no more entries) but it is still referenced by FileOne. IOW when you print it again you get nothing or a completely different entry. If you want to keep the current name you have to copy it somewhere else (depending on the object used).
  • dbpagedbpage Posts: 217
    edited 2014-10-10 07:55
    Notice there are 2 calls to statusVal[x] := SD.NextFileInfo("N"). FileOne and FileTwo could have different values.

    The statements VGAtext.Str (FileOne) and VGAtext.str (FileTwo) attempt to print zero-terminated byte arrays.

    Assuming FileOne and File two are zero-terminated strings, FileOne := StatusVal[X] and FileTwo := StatusVal[X] assigns only one byte to FileOne and FileTwo, respectively. Use bytemove to copy strings.
Sign In or Register to comment.