5 Replies Latest reply on Jan 4, 2007 6:11 PM by sl0beck

    Function to find variables data type?

    l810c
      Is there a way to find a variable's data type?

      I've created a QuickSort routine for an associative array. Right now it's just sorting alphabetically. I send it a 'column name' and it sorts by that 'column'. I want to find by the variable name(this is all in a class file) what that variables type is so that I can handle numbers and dates.
        • 1. Re: Function to find variables data type?
          Level 7
          try

          trace (typeof (myObjectOrVariable));



          --
          -------------------------------
          Remove '_spamkiller_' to mail
          -------------------------------


          • 2. Re: Function to find variables data type?
            Glazer
            Don't know if this will help, but the DataGrid component has a built in method "sortItemsBy", which could be useful:
            ListPanel is an instance of a DataGrid
            ListPanel.dataProvider.sortItemsBy(ListPanel.columnNames[0], null, Array.NUMERIC | Array.DESCENDING);
            • 3. Re: Function to find variables data type?
              l810c Level 1
              Thanks,
              typeof did the trick. I can't believe I could not track that down. I searched for hours.

              Couldn't use the datagrid sort as this is hundreds of records and I've added a custom paging to my datagrid that only show 20 records at a time.
              • 4. Re: Function to find variables data type?
                Level 7
                Great - you're welcome.

                --
                -------------------------------
                Remove '_spamkiller_' to mail
                -------------------------------


                • 5. Re: Function to find variables data type?
                  sl0beck
                  I've been trying to figure this out as well. I have some data structures - linked list and variants. They work really well except that there seems to be no way to determine the type of an object. What I thought would be to read the name of the constructor function. but I can't seem to do that either. If anyone knows C++ and knows "typedef" understands what I'm trying to replicate.
                  With data structures in C++ one preserves the type of the objects going in and out of a list. For instance, If I have a Linked List of AddressCards. In C++, before instantiating a new list, I can define a type with: typedef ListItemType AddressCard. Then INSIDE the implementation code for the List, I can have the methods that return list items look like this: public function retrieve( index:Number ):ListItemType -- Voi la! no need to type the items like var aCard:AddressCard = AddressCard(List.retrieve(0)); you can trust that the list will pass back items of the type you specified with the typedef statement. Anywho.. I know that's a little advanced, but if any gurus out there can give me a tip, or tell me to give up.