5 Replies Latest reply on Aug 20, 2012 6:27 AM by IvanJoghi

    How to cast a (custom) string value to a number

    IvanJoghi

      Hello fellow Flex'ers,

       

      I have a question regarding a revision number value which we respresent in our application as 2 digit number.

       

      We are using 01-99 for revisioning, the number should be incremented each update.
      I am adding document A with revision 01 (lowest revision), when finding this document and updating it I wish for my array to only show revision 02-99.
      Basically I wish to remove the old values from my array. in my documentnumber.as file the revision is set as a string value.

       

      My count function looks as follows (the data is being sent as XML):

       




      [Bindable]



      public var revisionDataprovider : ArrayCollection = new ArrayCollection();







      [Bindable]



      public var revisionUpdateDataprovider : ArrayCollection = new ArrayCollection();

       

                                                 private function count():void

                                                 {             

                                                                  var i : int = 1

                                                                  for (i; i < 100; i++)

                                                                  {

                                                                                 var revisionVersion : String = "" + i;

                                                                                 var revisionUpdateVersion : String = "" + i;

                                                                                 if (revisionVersion.length != 2 )

                                                                                 {

                                                                                                revisionVersion = "0" + revisionVersion;

                                                                                 }

                                                                                 revisionDataprovider.addItem(revisionVersion);

                                                                                 trace("adding item: " + revisionVersion)

                                                                                 if (revisionUpdateVersion.length != 2 )

                                                                                 {

                                                                                                revisionUpdateVersion = "0" + revisionUpdateVersion;

                                                                                 }

                                                                                 revisionUpdateDataprovider.addItem(revisionUpdateVersion);

                                                                                 trace("adding item: " + revisionVersion)

                                                                  }

                                                   }

       

      What I want is that revisionUpdateVersion starts with the value from the old version which is set by the database as the value:pm.fml.documentNumberOld.revision

       

      pm.fml.documentNumberOld.revision is the value in XML which is currently a string, it will not add up properly since it will add the revisionUpdateVersion as String {"" + 1} which will generate 011. I wish to casthe old revision to a number 01 = 1 (as int/number which will then count 1 + 1 = 2 and then the function will make it 02 by adding the 0+ revision version.

       

      To clarify revisionVersion is used to generate the document revision and revisionUpdateVersion to update the created document.

       

      I apologize if my question is vague. However I tried many things and cannot get it to work. I hope someone knows the answer

       

      Thank you all in advance,

       

      With kind regards,
      Ivan Joghi

        • 1. Re: How to cast a (custom) string value to a number
          BBlommers Level 2

          You could use the 'parseInt(..)' method to convert the revisionVersion to a number.

           

          I.e.:

           

          var revisionVersionNumber:int = parseInt(pm.fml.documentNumberOld.revision);

          var rivisionUpdateVersionNumber:int = revisionVersionNumber + 1;

          var revisionUpdateVersion:String = ""+revisionUpdateVersionNumber;

          if (revisionUpdateVersionNumber<10) {

               revisionUpdateVersion = "0"+revisionUpdateVersion;

          }

          1 person found this helpful
          • 2. Re: How to cast a (custom) string value to a number
            IvanJoghi Level 1

            Will try it asap
            Thanks for the response!

            • 3. Re: How to cast a (custom) string value to a number
              IvanJoghi Level 1

              Hello BBlommers,

               

              You solution was very helpful, thank you for the information!

               

              Now the array is being build properly however the data is only given after I hit the "retrieve" button twice.

              Basically I am using a retrieve action to get information about a document which has a revision.

               

              This revision is filled in a variable but for some reason it is being filled after the array wants to be build.

              This results in a non working array, hitting the button twice will give the value back properly.

               

              Basically I am using a variable called:

              pm.fml.documentNumber

               

              Because I have 2 other documentsnumber variables at updating

              Old and New, I have the original documentNumber which is "filled" at creating a document which houses a documentNumber.

              Since it is one and the same form I am making a copy of this information when retrieving it:

              DocumentNumber will be DocumentNumberOld (here the original values are shown and are non editable) and DocumentNumberNew (here you can set new values by filling in the fields).

               

              Everything works fine except for the fact I cannot seem to set the value documentNumberOld.revision to be used in the array so the form DocumentNumberNew is showing the correct revision number which is the old revision number + 1 (count).


              I hope I explain it good enough so it is understandable, if not please let me know so I can adjust the post.

               

              Thank you all in advance!

               

              With kind regards,

              Ivan Joghi

              • 4. Re: How to cast a (custom) string value to a number
                BBlommers Level 2

                Well, I thínk I understand what you're trying to say.. But it's impossible to pinpoint the problem with just this information.

                Could you post the code from where the user hits the Retrieve-button, up to the point where the documentNumberOld.revision-value cannot be set?

                1 person found this helpful
                • 5. Re: How to cast a (custom) string value to a number
                  IvanJoghi Level 1

                  Hi BBlommers,

                   

                  I solved the problem by making a workaround for the search(); function!
                  Thank you for your time and help, without your help it would have taken me much more time

                   

                  With best regards,
                  Ivan Joghi