Skip navigation
IvanJoghi
Currently Being Moderated

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

Aug 6, 2012 1:23 AM

Tags: #flex #3.5 #string_to_number

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

 
Replies
  • Currently Being Moderated
    Aug 6, 2012 4:09 AM   in reply to IvanJoghi

    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;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2012 12:53 AM   in reply to IvanJoghi

    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?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points