6 Replies Latest reply on Feb 20, 2009 12:48 AM by Newsgroup_User

    Too many repetitions

    Almudever Level 1
      My problem is the next:
      I have to repeat many times the same code for open different txt with fileIO and a chunck of code is the next. How I can reduce the repetitions? I tried with repeat loop but it doesn't work. Can you help me?
      The pattern whic is repeated is:

      myFile01 = xtra ("fileio").new()
      openFile(myFile01,the moviePath&"Test"&fileSep&"Tema_1"&fileSep&"t01.txt",1)
      nada = readWord(myFile01)
      titulo_01 = readLine(myFile01)

      if titulo_01 = VOID then

      continue
      else
      Q=1
      testList.add("myFile01")

      ---------------------------------------------------------------------------
      myFile02 = xtra ("fileio").new()
      openFile(myFile02,the moviePath&"Test"&fileSep&"Tema_1"&fileSep&"t02.txt",1)
      nada = readWord(myFile02)
      titulo_02 = readLine(myFile02)

      if titulo_02=VOID then

      continue
      else
      Q=2
      testList.add("myFile02")

      ---------------------------------------------------------------------------
      myFile03 = xtra ("fileio").new()
      openFile(myFile03,the moviePath&"Test"&fileSep&"Tema_1"&fileSep&"t03.txt",1)




      And so, and so until 50 times
        • 1. Re: Too many repetitions
          Level 7
          I don't condone repeat loops like this, I would make a handler out of this
          with a parameter for the file name and call it from an exitFrame handler.
          But in leiu of that much effort, here's my suggestion along the lines of
          what you say you've already tried. I've added a few lines that will break
          up some of the lengthier lines and might add some clarity (I hope). I
          tested this with 4 text files. I noticed you're doing nothing with nada.
          Also, my files were made up of one line "aslkdjfa 1" with the last character
          changing from 1 to 4 respectively. I noticed that the first bunch of
          letters read into nada and titulo_01's value was " 1", " 2" etc. I'm not
          sure why this is, it's obviously the way readWord and readLine work. But
          I'll leave that part to you.

          myFile01 = xtra ("fileio").new()
          testList = []
          repeat with FileNum = 1 to 4
          -- convert FileNum into a two character string that includes a leading
          zero
          fileNumStr = "0" & fileNum.string -- the string conversion isn't really
          needed but if clarifies the code
          fileNumStr = fileNumStr.char [fileNumStr.length - 1..fileNumStr.length]
          newFileName = "t" & fileNumStr & ".txt"
          textFilePath = the moviePath & newFileName
          openFile(myFile01,textFilePath ,1)
          nada = readWord(myFile01)
          titulo_01 = readLine (myFile01)

          if titulo_01 = VOID then
          next repeat
          else
          Q=1
          testList.add (titulo_01)
          end if
          closeFile (myFile01)
          end repeat
          myFile01 = 0
          put testList

          end





          --
          Craig

          "Almudever" <webforumsuser@macromedia.com> wrote in message
          news:gne3gf$p3e$1@forums.macromedia.com...
          > My problem is the next:
          > I have to repeat many times the same code for open different txt with
          > fileIO
          > and a chunck of code is the next. How I can reduce the repetitions? I
          > tried
          > with repeat loop but it doesn't work. Can you help me?
          > The pattern whic is repeated is:
          >
          > myFile01 = xtra ("fileio").new()
          > openFile(myFile01,the
          > moviePath&"Test"&fileSep&"Tema_1"&fileSep&"t01.txt",1)
          > nada = readWord(myFile01)
          > titulo_01 = readLine(myFile01)
          >
          > if titulo_01 = VOID then
          >
          > continue
          > else
          > Q=1
          > testList.add("myFile01")
          >
          > ---------------------------------------------------------------------------
          > myFile02 = xtra ("fileio").new()
          > openFile(myFile02,the
          > moviePath&"Test"&fileSep&"Tema_1"&fileSep&"t02.txt",1)
          > nada = readWord(myFile02)
          > titulo_02 = readLine(myFile02)
          >
          > if titulo_02=VOID then
          >
          > continue
          > else
          > Q=2
          > testList.add("myFile02")
          >
          >
          > ---------------------------------------------------------------------------
          > myFile03 = xtra ("fileio").new()
          > openFile(myFile03,the
          > moviePath&"Test"&fileSep&"Tema_1"&fileSep&"t03.txt",1)
          >
          >
          >
          >
          > And so, and so until 50 times
          >


          • 2. Re: Too many repetitions
            Almudever Level 1
            The problem is already solved but I don't know what is the meaning of: ?

            fileNumStr = fileNumStr.char [fileNumStr.length - 1..fileNumStr.length]

            I would like a definition of it
            • 3. Re: Too many repetitions
              Almudever Level 1
              The problem is already solved but I don't know what is the meaning of: ?

              fileNumStr = fileNumStr.char [fileNumStr.length - 1..fileNumStr.length]

              I would like a definition of it
              • 4. Re: Too many repetitions
                Level 7

                "Almudever" <webforumsuser@macromedia.com> wrote in message
                news:gnksr2$cap$1@forums.macromedia.com...
                > The problem is already solved but I don't know what is the meaning
                > of: ?
                >
                > fileNumStr = fileNumStr.char [fileNumStr.length -
                > 1..fileNumStr.length]
                >
                > I would like a definition of it
                >

                Here you go:
                ;)


                char...of

                Syntax

                textMemberExpression.char[whichCharacter]
                char whichCharacter of fieldOrStringVariable
                textMemberExpression.char[firstCharacter..lastCharacter]
                char firstCharacter to lastCharacter of fieldOrStringVariable
                Description

                Keyword; identifies a character or a range of characters in a chunk
                expression. A chunk expression is any character, word, item, or line
                in any source of text (such as field cast members and variables) that
                holds a string.

                An expression using whichCharacter identifies a specific
                character.

                An expression using firstCharacter and lastCharacter identifies a
                range of characters.



                The expressions must be integers that specify a character or range of
                characters in the chunk. Characters include letters, numbers,
                punctuation marks, spaces, and control characters such as Tab and
                Return.

                You can test but not set the char...of keyword. Use the put...into
                command to modify the characters in a string.

                Example

                This statement displays the first character of the string $9.00:

                put ("$9.00").char[1..1]
                -- "$"Example

                This statement displays the entire string $9.00:

                put ("$9.00").char[1..5]
                -- "$9.00"Example

                This statement changes the first five characters of the second word in
                the third line of a text cast member:

                member("quiz").line[3].word[2].char[1..5] = "?????"See also

                mouseMember, mouseItem, mouseLine, mouseWord



                begin 666 bullet.gif
                M1TE&.#EA" `(`*(``/___\?'QU]?7P\/#P```````````````"P`````" `(
                8```#$@BZW"Q#/$*E&I2,);)5T.<`"0`[
                `
                end

                • 5. Re: Too many repetitions
                  Level 7
                  > fileNumStr = fileNumStr.char [fileNumStr.length - 1..fileNumStr.length]

                  This expression sets the variable named 'fileNumStr' equal to the last
                  character of the variable named 'fileNumStr' - in effect it trims a
                  string to a single character, being the last character of the original
                  string
                  • 6. Re: Too many repetitions
                    Level 7
                    Sean Wilson wrote:
                    >> fileNumStr = fileNumStr.char [fileNumStr.length -
                    >> 1..fileNumStr.length]
                    >
                    > This expression sets the variable named 'fileNumStr' equal to the last
                    > character of the variable named 'fileNumStr' - in effect it trims a
                    > string to a single character, being the last character of the original
                    > string

                    Or
                    fileNumStr=the last char of fileNumStr

                    Andrew